我正在使用最新的 AFNetworking
查询我的服务器。
我的服务器端 PHP 正在发送一个 PHP 相关的错误,但我看不到错误是什么(所以我可以调试它),因为 AFNetworking 需要一个 JSON。
谁能告诉我如何才能看到完整的 HTTP 结果。我研究过,我知道与 success
/fail
block 中的 operation.responseString
有关,我当前的 block 没有 AFHTTPRequestOperation* 操作
,我无法以某种方式将它添加为另一个 block 变量。
非常感谢您的帮助。
下面的代码使用了
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.";
最佳答案
不要使用AFJSONRequestOperation
,只需使用AFHTTPRequestOperation
。
关于ios - AFNetworking 获取完整的 http 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18385810/