Reputation: 75
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);
}
Upvotes: 1
Views: 42
Reputation: 50099
set the content type of your request:
[req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
Upvotes: 2