The error NSLocalizedDescription = Expected status code in (200-299), got 400 is reported in the iOS post request.

Source: Internet
Author: User

The error NSLocalizedDescription = Expected status code in (200-299), got 400 is reported in the iOS post request.

When AFNetworking postJSON data is used, I am prompted at the beginning: // Error Domain = NSURLErrorDomain Code =-1007 "too rewrite HTTP redirects", which is a multi-targeting problem.

Later, after I changed it, I reported an error // NSLocalizedDescription = Expected status code in (200-299), got 400

Solution:

NSString * pathStr = @ "http://api.XXX.com/provider ";

NSDictionary * jsonObject ={ @ "key": @ "d85c713ef6704d651c7ce", @ "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 );
}];

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.