AFNetworking请求数据总是返回错误的修改
2020-11-15 15:53
标签:des http java strong 数据 io
最近我看到很多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= "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); }]; 然后运行 成功 ~! 不用谢小编,小编的名字叫雷锋~! AFNetworking请求数据总是返回错误的修改,搜素材,soscw.com AFNetworking请求数据总是返回错误的修改 标签:des http java strong 数据 io 原文地址:http://www.cnblogs.com/gaopengname/p/3698748.html
文章标题:AFNetworking请求数据总是返回错误的修改
文章链接:http://soscw.com/index.php/essay/21470.html