• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problems with NSURLRequest and HTTP POST Form Data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Newbie Q : getting rid of MyDocument
  • Next by Date: Re: NSTokenField - workaround for paste or drop vs. beginEditing and bindings?
  • Previous by thread: Re: Programmatically restarting Mac OS X
  • Next by thread: Re: Problems with NSURLRequest and HTTP POST Form Data
  • Index(es):
    • Date
    • Thread