Create an NSMutableURLRequest
object, set the HTTPMethod
to @"POST"
, put the parameters in the HTTP body as a properly formatted string — the same as GET parameters:
[request setHTTPBody:@"subject=foo&message=lorem%20ipsum"];
Send the request using NSURLConnection
and check for an error:
NSHTTPURLResponse *urlResponse = nil;
NSError *error = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
if (!responseData || urlResponse.statusCode != 200) {
NSLog(@"error: %@", error); // probably want to also tell the user that the message failed
}