I would like to make the following request from my application:
AFHTTPRequestOperationManager *requestManager = [[AFHTTPRequestOperationManager alloc] init]; requestManager.responseSerializer.acceptableContentTypes = [requestManager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"]; requestManager.requestSerializer = [AFJSONRequestSerializer serializer]; [requestManager POST:urlString parameters:aParameters constructingBodyWithBlock:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"%@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error: %@", error); }];
Where aParameters is an NSDictionary with the following content:
NSDictionary *urlParams = @{@"username" : anUser.userName, @"password" : anUser.password};
When I make a request from my application with user input "anUsername" and "aPassword", I get the following log for the body in my servlet:
--Boundary+5738A89B2C391231 Content-Disposition: form-data; name="password" aPassword --Boundary+5738A89B2C391231 Content-Disposition: form-data; name="username" anUsername --Boundary+5738A89B2C391231-- multipart/form-data; boundary=Boundary+5738A89B2C391231
I got the impression that using AFJSONRequestSerializer would send my request in the appropriate format, but as the log shows this, it multipart / form data. It is very difficult for me to parse this request (I parse it in Java on the server side), so my question is: is it possible to send json to the body of my request? Something like that:
{ "userName" : "anUsername", "password" : "aPassword" }
Any help would be appreciated.
source share