Problems with NSURLRequest and HTTP POST Form Data
Problems with NSURLRequest and HTTP POST Form Data
- Subject: Problems with NSURLRequest and HTTP POST Form Data
- From: Brant Sears <email@hidden>
- Date: Tue, 13 Jun 2006 16:48:07 -0400
Hi. I'm having some problems posting form data from my application.
I'm not sure what the problem is - perhaps it is the way that I have
the POST data formatted, or perhaps something else. I'm trying to
simulate a simple form that has two form fields called "field1" and
"field2". Here's what I'm trying to do:
- (void)myAction:(id)sender
{
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:@"http://192.168.4.136:62103"]];
char * myInfo = "field1=xyzzy&field2=plugh";
NSData * postdata = [NSData dataWithBytes:myInfo length:strlen
(myInfo)];
[request setHTTPBody:postdata];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded"
forHTTPHeaderField:@"Content-Type"];
NSURLResponse * response;
NSError * error;
NSData * myData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
NSString * myString = [NSString stringWithCString: [myData bytes]
length: [myData length]];
printf("%s\n", [myString cString]);
}
Is there a different way that I need to be formatting this, or is
there something else wrong?
Thanks.
Brant Sears
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden