简体   繁体   English

iPhone +以XML格式将数据从iPhone发送到服务器

[英]iPhone + sending data from iPhone to server as XML format

I am developing one iPhone application where I need to send some data (in XML format) from iPhone to server, on the server side I will parse that XML and get data for each XML node and than use them as per my requirement. 我正在开发一个iPhone应用程序,我需要从iPhone向服务器发送一些数据(XML格式),在服务器端,我将解析该XML并获取每个XML节点的数据,然后根据我的要求使用它们。

My question is: 我的问题是:

  1. How will I form the XML file on iPhone? 我将如何在iPhone上形成XML文件?
  2. How will I send that XML file to server? 我如何将XML文件发送到服务器?

Which methods I will use. 我将使用哪种方法。

Regards, Pratik 此致,Pratik

  1. I'm not sure what kind of data you're putting in your XML file, but I'd just create it with an NSMutableString, then change it to an NSData when you're ready to upload it to the server. 我不确定你在XML文件中放入了什么类型的数据,但我只是用NSMutableString创建它,然后在准备好将它上传到服务器时将其更改为NSData。

  2. create an NSURLRequest to your server and set the HTTPMethod to POST. 为您的服务器创建一个NSURLRequest并将HTTPMethod设置为POST。 Set the Content-Type to "multipart/form-data". 将Content-Type设置为“multipart / form-data”。 Add the XML file to your HTTPBody setting it's MIME type as text/plain. 将XML文件添加到HTTPBody设置,将其MIME类型设置为text / plain。

Here's some info on creating an NSURLRequest for uploading files: http://www.cocoadev.com/index.pl?HTTPFileUpload 以下是创建用于上传文件的NSURLRequest的一些信息: http//www.cocoadev.com/index.pl? HTTPTPileUpload

Oh, and BTW, they encoded their data using NSASCIIStringEncoding, you'll want to change that to NSUTF8StringEncoding. 哦,BTW,他们使用NSASCIIStringEncoding对数据进行编码,您需要将其更改为NSUTF8StringEncoding。

To form the XML file on iPhone, why don't you use KissXML ? 要在iPhone上形成XML文件,为什么不使用KissXML

To send the XML file to server, why don't you use ASIHTTPRequest (ASIFormDataRequest class)? 要将XML文件发送到服务器,为什么不使用ASIHTTPRequest (ASIFormDataRequest类)?

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

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