一盞燈, 一片昏黃; 一簡書, 一杯淡茶。 守著那一份淡定, 品讀屬于自己的寂寞。 保持淡定, 才能欣賞到最美麗的風(fēng)景! 保持淡定, 人生從此不再寂寞

- 使用AFNetworking進(jìn)行post請求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:@"[http://www.xiushuang.com/client/index.php?s=/Portal/p_banner/appinfo/comxiushuanglol_339_xs_android/index.json](http://www.xiushuang.com/client/index.php?s=/Portal/p_banner/appinfo/comxiushuanglol_339_xs_android/index.json)" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"JSON : %@",responseObject);
}failure:^(AFHTTPRequestOperation *operation, NSError *error){
NSLog(@"Error : %@",error);
}];
使用AFNetworking3.0時遇到以下問題 :
Error : Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo=0x8f85590 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x8f15f30> { URL: [http://www.xiushuang.com/client/index.php?s=/Portal/p_banner/appinfo/comxiushuanglol_339_xs_android/index.json](http://www.xiushuang.com/client/index.php?s=/Portal/p_banner/appinfo/comxiushuanglol_339_xs_android/index.json) } { status code: 200, headers {
"Cache-Control" = "maxage=3600";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "text/plain; charset=utf-8";
Date = "Tue, 07 Oct 2014 06:29:12 GMT";
Expires = "Tue, 07 Oct 2014 07:29:12 GMT";
"Last-Modified" = "Tue, 07 Oct 2014 06:26:13 GMT";
Server = "nginx/1.2.9";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
} }
此時需要修改AFNetworking可接收的Content-Type,前往AFNetworking源代碼目錄找到AFURLResponseSerialization.m文件將里面的代碼:
self.acceptableContentTypes =[NSSetsetWithObjects:@"application/json",@"text/json",@"text/javascript",nil];
修改為:
self.acceptableContentTypes =[NSSetsetWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",nil];
self.acceptableContentTypes =[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript" , @"text/plain" , nil];