Since I'm new to iOS developing, I need your help..
由于我是iOS新手,我需要你的帮助..
I need to send POST data from an iPad app to a webserver that will process the data. In HTML it would be easily done by a form like this:
我需要将POST数据从iPad应用程序发送到将处理数据的网络服务器。在HTML中,可以通过以下形式轻松完成:
<form name="myform" action="myphpfile.php" method="post">
<input type="hidden" name="input1" value="1" />
<input type="hidden" name="input2" value="2" />
<input type="hidden" name="json" value="{"a":"1","b":"2"}" />
</form>
As you can see I have two "normal" input and one containing a json formatted array of values.
如您所见,我有两个“普通”输入,一个包含json格式的值数组。
How can I send the data in my app and handle the json in the right way to avoid issues?
如何在我的应用程序中发送数据并以正确的方式处理json以避免问题?
Thank you in advance for your help!
预先感谢您的帮助!
1 个解决方案
#1
0
Read up on NSURLRequest. It exposes the HTTPMethod fields and HTTPBody. You'll want to encode your JSON as NSData and set it as the request body, your HTTPMethod will be "POST", obviously.
阅读NSURLRequest。它公开了HTTPMethod字段和HTTPBody。您需要将JSON编码为NSData并将其设置为请求主体,显然您的HTTPMethod将是“POST”。
#1
0
Read up on NSURLRequest. It exposes the HTTPMethod fields and HTTPBody. You'll want to encode your JSON as NSData and set it as the request body, your HTTPMethod will be "POST", obviously.
阅读NSURLRequest。它公开了HTTPMethod字段和HTTPBody。您需要将JSON编码为NSData并将其设置为请求主体,显然您的HTTPMethod将是“POST”。