简体   繁体   English

从iPhone到服务器的XML POST

[英]XML POST to Server from iPhone

I have an XML that I need to send to another website using PHP. 我有一个XML,需要使用PHP发送到另一个网站。 What would be the best way to do this on the iPhone? 在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. XML需要根据用户的选择进行格式化,然后使用服务器上的PHP发送到其他服务器。 Any suggestions? 有什么建议么?

Disclaimer: I know absolutely nothing about NSURLConnection as @Mat alluded to or how to POST data from an iPhone. 免责声明: 我对NSURLConnection完全一无所知,因为@Mat被提及或如何从iPhone发布数据。

how do i format it using PHP so that i can send it to a webserver as an XML? 如何使用PHP格式化它,以便可以将它作为XML发送到Web服务器?

In PHP you can convert the $_POST data to XML by using DOMDocument . 在PHP中,您可以使用DOMDocument将$ _POST数据转换为XML。 The other server most likely also requires you to POST the XML data. 其他服务器很可能也需要您发布XML数据。 In that case you can use cURL 在这种情况下,您可以使用cURL

Just send a regular POST request. 只需发送常规的POST请求即可。

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];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM