iOS中,修改AFNetworking源文件可接收text/plain的方法"Request failed: unacceptable content-type: text/plain"

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:@"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);
    }];

使用AFNetworking2.4.1时遇到以下问题 :

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 } { 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]; 


更多参考 :

What is the correct JSON content type?



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
javax.net.ssl.SSLHandshakeException: Unacceptable certificate错误是由于访问的域名证书不在有效期内或者JDK不存在该证书的信任导致的。解决这个问题的方法有以下几种: 1. 更新JDK信任库:可以通过更新JDK的信任库来解决该问题。可以使用以下命令将证书添加到信任库: ```shell keytool -import -alias <alias> -keystore <path_to_truststore> -file <path_to_certificate> ``` 其,`<alias>`是证书的别名,`<path_to_truststore>`是信任库的路径,`<path_to_certificate>`是证书的路径。 2. 忽略证书验证:在某些情况下,可以选择忽略证书验证来解决该问题。可以通过以下代码来实现: ```java TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) { } public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) { } } }; SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, trustAllCerts, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); ``` 3. 添加自定义信任证书:如果访问的是自签名证书或者不受信任的证书,可以将该证书添加到信任库。可以使用以下命令将证书添加到信任库: ```shell keytool -import -alias <alias> -keystore <path_to_truststore> -file <path_to_certificate> ``` 其,`<alias>`是证书的别名,`<path_to_truststore>`是信任库的路径,`<path_to_certificate>`是证书的路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值