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 d开发者_高级运维ifferent server using PHP that is on my server. Any suggestions?
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=%@¶m2=%@", aUrlEncodedString, anotherUrlEncodedString] dataUsingEncoding:NSUTF8StringEncoding];
NSURLResponse* response = nil;
NSError* error = nil;
NSData* responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
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
精彩评论