1

The below curl line works in terminal, but I cant figure out how to correctly translate it into NSURL

curl -X PUT http://user:pass@localhost:3000/update/564a3f1ff72fe641a8000013/? -d firstName=Adam

This is the code I am rocking so far and it connects but creates fields with the value NIL instead of udpateing them with new value

NSString *authString = [NSString stringWithFormat:@"%@:%@%c",@"user", @"pass", '@'];

NSData *postData = [@"firstName=Adam" dataUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@localhost:3000/update/564a3f1ff72fe641a8000013/?",authString]];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
[req setHTTPMethod:@"PUT"];
[req setHTTPBody:postData];

NSError *err = nil;
NSHTTPURLResponse *res = nil;
NSData *retData = [NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err];
if (err)
{
    //handle error
    NSLog(@"BOOO : %@",err);
}
else
{
    //handle response and returning data
    NSLog(@"YAYA : %@",err);
}

1 Answer 1

2

set the content type of your request:

[req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
Sign up to request clarification or add additional context in comments.

3 Comments

No visible @interface for 'NSMutableURLRequest' declares selector 'setContentType:'
EDITED - sorry, I wrote how I do it -- as I have a category for that ;) but in the end you wanna set the header
[req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; That worked for me thank you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.