Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append data to a POST NSURLRequest

How do you append data to an existing POST NSURLRequest? I need to add a new parameter userId=2323.

like image 225
Tim Avatar asked May 27 '11 07:05

Tim


1 Answers

If you don't wish to use 3rd party classes then the following is how you set the post body...

NSURL *aUrl = [NSURL URLWithString:@"http://www.apple.com/"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl                                          cachePolicy:NSURLRequestUseProtocolCachePolicy                                      timeoutInterval:60.0];  [request setHTTPMethod:@"POST"]; NSString *postString = @"company=Locassa&quality=AWESOME!"; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];  NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request                                                               delegate:self]; 

Simply append your key/value pair to the post string

like image 169
Simon Lee Avatar answered Oct 16 '22 20:10

Simon Lee