iPhone +以XML格式将数据从iPhone发送到服务器 [英] iPhone + sending data from iPhone to server as XML format

查看:258
本文介绍了iPhone +以XML格式将数据从iPhone发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,我需要从iPhone向服务器发送一些数据(XML格式),在服务器端,我将解析该XML并获取每个XML节点的数据,然后根据我的要求使用它们。

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.

我的问题是:


  1. 我将如何形成XML文件iPhone?

  2. 我如何将XML文件发送到服务器?

我将使用哪种方法使用。

Which methods I will use.

问候,Pratik

推荐答案


  1. 我不确定你在XML文件中放入了什么类型的数据,但是我只是用NSMutableString创建它,然后当你准备好将它上传到NSData时将其改为NSData。服务器。

  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.

为您的服务器创建一个NSURLRequest并将HTTPMethod设置为POST。将Content-Type设置为multipart / form-data。将XML文件添加到HTTPBody设置,将其MIME类型设置为text / plain。

create an NSURLRequest to your server and set the HTTPMethod to POST. Set the Content-Type to "multipart/form-data". Add the XML file to your HTTPBody setting it's MIME type as text/plain.

以下是有关创建NSURLRequest的一些信息上传文件: http://www.cocoadev.com/index.pl?HTTPFileUpload

Here's some info on creating an NSURLRequest for uploading files: http://www.cocoadev.com/index.pl?HTTPFileUpload

哦,BTW,他们使用NSASCIIStringEncoding对数据进行编码,您需要将其更改为NSUTF8StringEncoding。

Oh, and BTW, they encoded their data using NSASCIIStringEncoding, you'll want to change that to NSUTF8StringEncoding.

这篇关于iPhone +以XML格式将数据从iPhone发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆