I'm pretty new to Xcode, and I'm trying to make a POST request. I searched on Google and found this AFNetworking library. I've read some documentation but they all say different things. So now I use their own example on a POST request and my code looks like this:
- (void)viewDidLoad {
[super viewDidLoad];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"fName": @"firstname", @"lName": @"lastname"};
[manager POST:@"http://00000.1111.ovh/api/Account/register" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
And then I get this error:
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={com.alamofire.serialization.response.error.response= { URL: http://00000.1111.ovh/api/Account/register } { status code: 400, headers { "Content-Length" = 159; "Content-Type" = "application/json; charset=utf-8"; Date = "Sun, 15 Nov 2015 12:11:57 GMT"; Server = "Microsoft-IIS/8.5"; "X-Powered-By" = "ASP.NET"; } }, NSErrorFailingURLKey=http://00000.1111.ovh/api/Account/register, com.alamofire.serialization.response.error.data=<7b226d65 73736167 65223a22 54686520 72657175 65737420 69732069 6e76616c 69642e22 2c226d6f 64656c53 74617465 223a7b22 6c6f6769 6e2e7573 65726e61 6d65223a 5b225468 65205573 6572206e 616d6520 6669656c 64206973 20726571 75697265 642e225d 2c226c6f 67696e2e 70617373 776f7264 223a5b22 54686520 50617373 776f7264 20666965 6c642069 73207265 71756972 65642e22 5d7d7d>, NSLocalizedDescription=Request failed: bad request (400)}
Hope someone can help me!
AFHTTPRequestOperationManager
isNSURLConnection
based (which is now deprecated), then use the very similarAFHTTPSessionManager
(which isNSURLSession
based). – Rob