When using afnetworking Postjson data, I just started to prompt me//error domain=nsurlerrordomain code=-1007 "Too many HTTP redirects", said to be a multi-directional problem
Then I changed it and then I got an error.//nslocalizeddescription=expected status code in (200-299), got 400
Workaround:
NSString *[email protected] "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 request times wrong nslocalizeddescription=expected status code in (200-299), got 400