美文网首页程序员
iOS中,修改AFNetworking源文件可接收text/pl

iOS中,修改AFNetworking源文件可接收text/pl

作者: 审判spp | 来源:发表于2017-05-10 09:33 被阅读0次

    一盏灯, 一片昏黄; 一简书, 一杯淡茶。 守着那一份淡定, 品读属于自己的寂寞。 保持淡定, 才能欣赏到最美丽的风景! 保持淡定, 人生从此不再寂寞

    • 使用AFNetworking进行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]; 
    

    相关文章

      网友评论

        本文标题:iOS中,修改AFNetworking源文件可接收text/pl

        本文链接:https://www.haomeiwen.com/subject/xaukettx.html