AFNetworking请求数据总是返回错误的修改
最近我看到很多AFNet的教程,我就在想怎么那么多人不明白怎么用AFNet。很多人回答的问题都是一样的怎么还有人不会用。我估计很多人都遇到了这个错误
我运行了 这段代码
AFHTTPRequestOperationManager * manager = [ AFHTTPRequestOperationManager manager ];
[manager GET:@"http://211.154.151.249:8866/ogPortal/getCarType.do"parameters:Nilsuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"%@",responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error===%@",error);
}];
这是返回的错误提示
AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x8a9b9b0> { URL: http://211.154.151.249:8866/ogPortal/getCarType.do } { status code: 200, headers {
"Content-Language" = "zh-HANS";
"Content-Type" = "text/html;charset=UTF-8";
Date = "Tue, 29 Apr 2014 02:40:01 GMT";
Server = "Apache-Coyote/1.1";
"Set-Cookie" = "JSESSIONID=CE41FCD6855EB887488C368B2952B798; Path=/ogPortal/; HttpOnly";
"Transfer-Encoding" = Identity;
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}
这段疑似是说 你这个 东西是text/html的 我现在不认识这个格式的 没有办法返回。
此时怎么办呢?
首先 我们全局搜索 self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",nil];
然后我们加上他不认识的格式 self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html"nil];
此时编译成功了吧!!
此处代码太多 少截取点啦~
014-04-29 10:45:21.067 AFNetWorkingNowText[3083:70b] {
msgCode = 0;
result = (
{
child = (
{
child = (
{
id = 954;
ischild = 1;
name = "2013\U6b3e 6.0L Coupe";
}
);
id = 126;
ischild = 0;
name = "A \U963f\U65af\U987f\U00b7\U9a6c\U4e01DB9";
},
{
child = (
{
id = 955;
ischild = 1;
name = "2007\U6b3e 6.0 Manual Coupe";
},
{
id = 956;
ischild = 1;
name = "2009\U6b3e 6.0 Touchtronic Coupe";
},
有人说 什么 改源代码??? 以后错了 怎么办~! 好吧 你要是不想改动源代码 此处也可以这么写
加上这么一句话 :( manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];)
AFHTTPRequestOperationManager * manager = [ AFHTTPRequestOperationManager manager ];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager GET:@"http://211.154.151.249:8866/ogPortal/getCarType.do"parameters:Nilsuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"%@",responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error===%@",error);
}];
然后运行 成功 ~! 不用谢小编,小编的名字叫雷锋~!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。