我有示例代码使用POST方法将密钥对值作为数组列表发送到HTTTP restful web服务,如下所示。如何在iPhone中实现HTTP Post作为android HTTPPost?
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
如何在iPhone中实现相同的Objective-C。 任何想法赞赏...
阅读['NSURLRequest']的文档(https://developer.apple.com/library/iOS/#documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/Reference/Reference.html)或使用简单包装像[AFNetworking](https://github.com/AFNetworking/AFNetworking) – rckoenes
可能的重复:http://stackoverflow.com/questions/3566516/simple-http-post-example-in-xcode – Mazyod