iPhone XML请求
我有一个 API,可以向服务器发送 XML 请求:
<?xml version="1.0" encoding="UTF-8"?>
<request type="handle" action="update">
<userdata>
<username>YourUsername</username>
<password>YourPassword</password>
</userdata>
<handledata type="PERSON" id="HandleId">
<name>Mustermann</name>
<firstname>Max</firstname>
<organization>Firma KG</organization>
<street>Musterstrasse 1</street>
<postalcode>11111</postalcode>
<city>Musterstadt</city>
<state>Niedersachsen</state>
<country>DE</country>
<email>[email protected]</email>
<phone>+43-111-111111</phone>
<fax>+43-111-111111</fax>
<remarks>remarks</remarks>
</handledata>
</request>
如何在 iPhone 上执行此操作?
I have an API which sends an XML Request to a server:
<?xml version="1.0" encoding="UTF-8"?>
<request type="handle" action="update">
<userdata>
<username>YourUsername</username>
<password>YourPassword</password>
</userdata>
<handledata type="PERSON" id="HandleId">
<name>Mustermann</name>
<firstname>Max</firstname>
<organization>Firma KG</organization>
<street>Musterstrasse 1</street>
<postalcode>11111</postalcode>
<city>Musterstadt</city>
<state>Niedersachsen</state>
<country>DE</country>
<email>[email protected]</email>
<phone>+43-111-111111</phone>
<fax>+43-111-111111</fax>
<remarks>remarks</remarks>
</handledata>
</request>
How do I do this on the iPhone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
libxml2
。我怀疑这是最快的方法。将其框架添加到您的项目中(请参阅 本文档)。在 XML 编写器的标头中,添加以下导入:
在实现中,编写一个方法来生成 XML。想必您将通过
NSData*
对象发送请求的字节,因此您可能会编写如下内容:我在这里有一个辅助方法,我用它来转换
const char *
进入xmlChar *
:You can use
libxml2
. I suspect it is the fastest approach. Add its framework to your project (see the "setting up your project" section of this document).In the header of your XML writer, add the following imports:
In the implementation, write a method to generate your XML. Presumably you'll be sending your request's bytes via an
NSData*
object, so you might write something like this:I have a helper method here that I use to convert
const char *
intoxmlChar *
:对于这样一个简单的结构,我会使用字符串格式。
I would use string formatting for such a simple structure.