Reputation: 5010
I'm learning to use AFNetworking
.
I know I can use AFHTTPClient
for making a POST request with json.
My question is: is there a way to make a standard POST request (that is, with a content type of application/x-www-form-urlencoded
)? My server backend doesn't accept json, because the client should use the same form for login via web.
In past I used ASIHTTPRequest
and I used this code:
url = [NSURL URLWithString:@"www.example.org/login/"];
request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:self.username forKey:@"username"];
[request setPostValue:self.password forKey:@"password"];
[request startAsynchronous];
Thanks!
Upvotes: 4
Views: 9936
Reputation: 5010
I've solved with [httpClient setParameterEncoding:AFFormURLParameterEncoding];
Reference: https://stackoverflow.com/a/8491782/719127
Upvotes: 6
Reputation: 11834
Just create a NSMutableURLRequest object and modify the HTTP-headers and body as per Apple documentation. This request object can then be used with the AFNetworking library.
Upvotes: 0