我有以下API調用:AFNetworking HTTP PUT請求
URL: /api/some-call
Method: PUT
PARAMS: No params
它只是一個簡單的PUT方法。我正嘗試使用AFNetworking來做到這一點,不幸的是,我失敗了。這是我現在所擁有的:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSMutableURLRequest *req = [httpClient requestWithMethod:@"PUT" path:@"" parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:req];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
} failure: ^(AFHTTPRequestOperation *operatn, NSError *error) {
NSLog(@"Failure");
}];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[queue addOperation:operation];
但是,這是行不通的。這是爲什麼?此外,什麼是path
應該在PUT
請求中?我已經嘗試了幾件事情,這是我現在最後的結果,我相信應該接近正確。
最後一個問題:AFNetworking
不使用ARC
。這是否意味着在NSOperationQueue
聲明的末尾仍然需要autorelease
?
編輯: 這是錯誤NSLog
:Failure Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 409" UserInfo=0x7a91fb0 {NSErrorFailingURLKey=*the url*/api/some-call, NSLocalizedDescription=Expected status code in (200-299), got 409}
你可以註銷錯誤,所以我們可以幫你嗎? 在失敗塊中使用NSLog(@「Error:%@」,error);並向我們顯示記錄的錯誤。 – steve0hh
已添加。你走了。謝謝! – darksky
已回答。請檢查下面的答案。 :) – steve0hh