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

I am involved in using AFNetworking .

I know that I can use AFHTTPClient to create a POST request using json.

My question is: is there a way to make a standard POST request (i.e. with the content type application/x-www-form-urlencoded )? My server server does not accept json, because the client must use the same login form through the web interface.

In the 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!

+4
source share
2 answers

I decided using [httpClient setParameterEncoding:AFFormURLParameterEncoding];

Link: fooobar.com/questions/476656 / ...

+6
source

Just create an NSMutableURLRequest object and change the HTTP headers and body according to Apple's documentation. This request object can then be used with the AFNetworking library.

0
source

Source: https://habr.com/ru/post/1396374/


All Articles