I am working on a POST request and have been using this answer. There is a lot of documentation NSUrlRequest (and connection) but I am having trouble figuring out why the request won't work.
I have performed a successful POST using an HTTP Dev Client using this code
entry.0.single=name&entry.1.single=location&entry.4.single=phoneNumber&entry.2.single=order????&pageNumber=0&backupCache=
The 4 variables (name, location, phoneNumber, order) are all linked to textFields in the app.
- (IBAction)placeOrder:(id)sender { NSURL *nsURL = [[NSURL alloc] initWithString:@"url"]; NSMutableURLRequest *nsMutableURLRequest = [[NSMutableURLRequest alloc] initWithURL:nsURL]; // Set HTTP method to POST [nsMutableURLRequest setHTTPMethod:@"POST"]; // Set up the parameters to send. NSString *paramDataString = [NSString stringWithFormat:@"%@=%@&%@=%@&%@=%@&%@=%@&pageNumber=0&backupCache=",@"entry.0.single", _name, @"entry.1.single", _location, @"entry.4.single", _phoneNumber, @"entry.2.single", _order]; // Encode the parameters to default for NSMutableURLRequest. NSData *paramData = [paramDataString dataUsingEncoding:NSUTF8StringEncoding]; // Set the NSMutableURLRequest body data. [nsMutableURLRequest setHTTPBody: paramData]; // Create NSURLConnection and start the request. NSURLConnection *nsUrlConnection=[[NSURLConnection alloc]initWithRequest:nsMutableURLRequest delegate:self]; [ nsUrlConnection start]; }
I think I might be missing something subtle but I have been pouring through stackoverflow and developer documentation. Any thoughts would be much appreciated. Thanks