0

I have been trying to send parameters as form data by setting content type as application/x-www-form-urlencoded into HTTPHeaderField but the request is not going through for only above content type, my code works for type application/json. So, I am not able to rectify the actual problem hence the request is not going through.

Below is my code ::

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager.requestSerializer setTimeoutInterval:60]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; [manager.requestSerializer setValue:requestAuthorization forHTTPHeaderField:@"Authorization"]; [manager.requestSerializer setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"]; [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [manager.requestSerializer setValue:[[[UIDevice currentDevice] identifierForVendor] UUIDString] forHTTPHeaderField:@"device_id"]; [manager.requestSerializer setValue:[[UIDevice currentDevice] systemVersion] forHTTPHeaderField:@"device_os"]; [manager.requestSerializer setValue:[[UIDevice currentDevice] systemName] forHTTPHeaderField:@"device_name"]; [manager POST:url parameters:parameters success:success failure:failure]; 

Any help would be much appreciated.

Thanks

1 Answer 1

1

It is given on the AFNetworking page on Github. AFNetworking Library

You can do this by simply using following example:-

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; NSDictionary *parameters = @{@"key": @"xxx"}; [manager POST:@"http://test.com" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject);} failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; 
Sign up to request clarification or add additional context in comments.

6 Comments

Do you want to upload any large file to server?
No, i just want to send parameters as form data, thats why I am setting [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
Please do not set this in your code and try:- [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
Still not able to go through, the API is accessible by Advance Rest client but not by AFNetworking i.e. not able to POST parameters as form data.
Perfect answer for me
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.