Fred Collins
Fred Collins

Reputation: 5010

AFNetworking: POST request with application/x-www-form-urlencoded

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

Answers (2)

Fred Collins
Fred Collins

Reputation: 5010

I've solved with [httpClient setParameterEncoding:AFFormURLParameterEncoding];

Reference: https://stackoverflow.com/a/8491782/719127

Upvotes: 6

Wolfgang Schreurs
Wolfgang Schreurs

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

Related Questions