4

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!

Daniel Rinser
  • 8,855
  • 4
  • 41
  • 39
Fred Collins
  • 5,004
  • 14
  • 62
  • 111

2 Answers2

6

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

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

Community
  • 1
  • 1
Fred Collins
  • 5,004
  • 14
  • 62
  • 111
0

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.

Wolfgang Schreurs
  • 11,779
  • 7
  • 51
  • 92