我正在使用最新版本的AFNetworking
查詢我的服務器。AFNetworking獲取完整的http響應
我的服務器端PHP發送一個PHP相關的錯誤,但我無法看到錯誤是什麼(所以我可以調試它)AFNetworking期待一個JSON。
任何人都可以告訴我如何看到完整的HTTP結果。我已經研究過,並且我知道這是success
/fail
塊中的operation.responseString
,我當前的塊沒有AFHTTPRequestOperation* operation
,我無法以某種方式將它添加爲另一個塊變量。
我真的很感謝一些幫助。
下面的代碼使用
NSURL *url = [[NSURL alloc]initWithString:URL];
AFHTTPClient *httpClient = [[AFHTTPClient alloc]initWithBaseURL:url];
NSURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:URLPATH parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
//...
}
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON){
NSLog(@"Inside the success block %@",JSON);
[[self delegate ]shareExerciseDone:JSON];
[[self delegate] activityIndicatorFinish];
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
NSLog(@"Response text is: %@", operation.responseString);
NSLog(@"json text is: %@", JSON);
NSLog(@"Request failed with error: %@, %@", error, error.userInfo);
[[self delegate] activityIndicatorFinish];
}];
[operation start];
錯誤
Request failed with error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0xc1b4520 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}, {
NSDebugDescription = "JSON text did not start with array or object and option to allow fragments not set.";
你在尋找'response.statusCode'還是'response.allHeaderFields'? [NSHTTPURLResponse文檔](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSHTTPURLResponse_Class/Reference/Reference.html) – danielbeard
不,我需要完整的HTML文本輸出PHP。我想看看它失敗的地方以及發送的內容不是JSON –