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