AFNetworking2.0后Post请求报错

报错信息如下:

error:Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo=0x7faddb024460 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7faddb0a4ed0> { URL: http://xhyj.bloveambition.com/index.php?r=patriarch/user/feedback } { status code: 200, headers {

    "Centent-Type" = "text/html;charset=UTF-8";

    Connection = "keep-alive";

    "Content-Type" = "text/html";

    Date = "Tue, 10 Feb 2015 08:14:17 GMT";

    Pragma = "no-cache";

    Server = "nginx/1.0.15";

    "Transfer-Encoding" = Identity;

    "X-Powered-By" = "PHP/5.3.3";

} }, NSErrorFailingURLKey=http://xhyj.bloveambition.com/index.php?r=patriarch/user/feedback, com.alamofire.serialization.response.error.data=<7b227374 61746522 3a317d>, NSLocalizedDescription=Request failed: unacceptable content-type: text/html}


解决办法:

2.0已经对各种方法做了优化,也不需要用AFJSONRequestOperation,2.0已经自带JSON解析。 
你可以用AFHTTPRequestOperationManager解决一切问题,2.0会对返回的JSON或者XML自动解析为字典的 

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];//设置相应内容类型

上面的报错内容类型是 "text/html":

/**
 *  5.19 意见反馈Post
 *
 *  @param id           用户id
 *  @param token        用户token
 *  @param content      反馈的文本信息
 *  @param successBlock
 */
+ (void)userFeedbackWithcontent:(NSString *)content
                   successBlock:(void(^)(BOOL isSuccess,NSDictionary *resultDic))successBlock
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];//设置相应内容类型
    
    NSDictionary *paramters = @{@"id": [self getUserId],@"token":[self getUserToken],@"content":content};
    
    NSLog(@"5.19 意见反馈Post paramters:%@",paramters);
    
    [manager POST:[NSString stringWithFormat:@"%@index.php?r=patriarch/user/feedback",kMainUrlString] parameters:paramters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"5.19 意见反馈Post:%@",responseObject);
        
        if ([responseObject[@"state"] intValue] == 1) {//请求成功,状态不一样
            
            successBlock(YES,responseObject);
        }else {
            
            successBlock(NO,responseObject);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        successBlock (NO,nil);
        NSLog(@"5.19 意见反馈POST请求error:%@",error);
        
    }];
    
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值