码迷,mamicode.com
首页 > 移动开发 > 详细

iOS post请求时报错NSLocalizedDescription=Expected status code in (200-299), got 400

时间:2015-05-08 14:59:28      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:ios   ios http请求头   post   

用AFNetworking postJSON数据的时候,刚开始提示我//Error Domain=NSURLErrorDomain Code=-1007 "too many HTTP redirects",说是多重定向问题

后来我改了之后又报错//NSLocalizedDescription=Expected status code in (200-299), got 400

解决办法:

   NSString *pathStr=@"http://api.XXX.com/provider" ;
    
    NSDictionary *jsonObject = @{@"key":@"5dc1203cd89d85c713ef6704d651c7ce",@"userId":@"123456654321"};
    
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:pathStr]];
    
    httpClient.parameterEncoding=AFJSONParameterEncoding;
    
    [httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
    
    [httpClient setDefaultHeader:@"Accept" value:@"application/json"];
    
    
    
//    NSMutableDictionary *params=[[NSMutableDictionary alloc]init];
//    
//    [params setObject:@"5dc1203cd89d85c713ef6704d651c7ce" forKey:@"key"];
//    
//    [params setObject:@"123456654321" forKey:@"userId"];
    
    [httpClient postPath:@"accessToken" parameters:jsonObject success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSLog(@"data=====%@",jsonObject);
        //NSString *responseStr = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSLog(@"responseString:%@",operation.responseString);
        //NSLog(@"Request Successful, response ‘%@‘", responseStr);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         NSLog(@"[HTTPClient Error]: %@", error);
    }];


iOS post请求时报错NSLocalizedDescription=Expected status code in (200-299), got 400

标签:ios   ios http请求头   post   

原文地址:http://blog.csdn.net/darongzi1314/article/details/45578455

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!