I am trying to use NSURLConnection to submit a form to a URL. My form requires the inclusion of a hidden field with a specific name and value. In HTML it would look like:
Code:
<form action="http://www.example.com/mail" enctype="multipart/form-data" method="POST">
<input type="text" name="mailfrom">
<input type="hidden" name="sendtoemail" value="destination-webmaster@example.com">
<input type="submit" value="Send Email">
</form>
I've found several threads on submitting general text fields (e.g. UITextField for entering an email address), but nothing covering how to include a hidden field that requires a specific name and value. Here's what I have so far:
Code:
NSString *post = nil;
post = [[NSString alloc] initWithFormat:@"message=%@",messageText.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"http://www.example.com/mail"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"multipart/form-data" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[ NSURLConnection connectionWithRequest:request delegate:self ];
[post release];
Thanks for any assistance.
PS-Am I going to run into trouble using "multipart/form-data" for the Content Type, instead of "application/x-www-form-urlencoded" which I see in most of the examples?