-1

I have an XML that I need to send to another website using PHP. What would be the best way to do this on the iPhone? The XML needs to be formatted based on the selections of the user, then sent to a different server using PHP that is on my server. Any suggestions?

Prajoth
  • 900
  • 3
  • 12
  • 26
  • take a look here http://stackoverflow.com/questions/2071788/iphone-sending-post-with-nsurlconnection – Mat Sep 28 '11 at 17:41
  • and how do i format it using PHP so that i can send it to a webserver as an XML? – Prajoth Sep 28 '11 at 17:45

2 Answers2

2

Disclaimer: I know absolutely nothing about NSURLConnection as @Mat alluded to or how to POST data from an iPhone.

how do i format it using PHP so that i can send it to a webserver as an XML?

In PHP you can convert the $_POST data to XML by using DOMDocument. The other server most likely also requires you to POST the XML data. In that case you can use cURL

Herbert
  • 5,698
  • 2
  • 26
  • 34
2

Just send a regular POST request.

NSString* aUrlEncodedString = @"some%20string";
NSString* anotherUrlEncodedString = @"foobar";
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://example.com/blah.php"]];
request.HTTPMethod = @"POST";
request.HTTPBody = [[NSString stringWithFormat:@"param1=%@&param2=%@", aUrlEncodedString, anotherUrlEncodedString] dataUsingEncoding:NSUTF8StringEncoding];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Icydog
  • 467
  • 2
  • 6