【发布时间】:2013-08-22 16:14:32
【问题描述】:
我正在使用AFNetworking 查询我的服务器,这是最新的版本。
我的服务器端 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 documentation -
不,我需要 PHP 输出的完整 HTML 文本。我想看看它失败的地方以及发送的不是 JSON 的内容
标签: ios objective-c cocoa-touch afnetworking