【发布时间】:2012-12-11 00:43:06
【问题描述】:
有人吗?):在过去的 2 个小时里,我遇到了一个让我摸不着头脑的问题,这很可能是我错过的一个非常简单的愚蠢事情。当我从操作@AFNetworking 调用响应字符串时,我不断收到构建错误......就像没有这样的财产......
请查看我的代码并解释我这次搞砸了什么:p.. 谢谢 :)
NSDictionary* paramDict = [NSDictionary dictionaryWithObjectsAndKeys:WebServicemd5Value, WebSermd5Variable, nil]
;
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:webServiceURL]];
[httpClient defaultValueForHeader:@"Accept"];
[httpClient postPath:@"method" parameters:paramDict success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response data: %@", responseObject);
NSLog(@"Reponse String: %@", operation);
// 打印操作会显示操作字典,包括响应字段,// 但是当我直接调用 operation.response 时,编译器不会构建,说明 // “AFHTTPRequestOperation 找不到属性”.. .. 最奇怪的事情,对吧?
NSString* responseString = [NSString stringWithUTF8String:[responseObject bytes]];
//.. Rest o f my Code....
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error retrieving data: %@", error);
}];
【问题讨论】:
-
我想在 NSLOG 中简单地打印 operation.response 而不是操作本身...
-
你是说,当你做 NSLog(@"Response object %@",operation.response); - 编译器抱怨,但是当你做 NSLog(@"Operation object %@",operation);它打印并且它具有响应作为其元素之一。你的控制台输出是什么。
-
您是否尝试过打印出单独的操作响应?例如打印出状态码
NSLog(@"Operation response status = %@", [NSHTTPURLResponse localizedStringForStatusCode:operation.response.statusCode]); -
@Srinkanth - 控制台输出是一系列十六进制数字......不像我预期的那样真的是字典......谢谢
-
@Adam Johnson:就是这样...我无法访问 operation.response,也无法访问 operation.response.statusCode... 很奇怪吧?感谢您的回复:-)
标签: ios networking afnetworking nsurlrequest