iOS UrlEncodedFormEntity等效

时间:2014-02-27 08:20:00

标签: android ios

此方法的iOS等效代码是什么?

public static String post(String url, String json_content) {
    try {
        HttpClient client = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("", json_content.toString()));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = client.execute(httppost);
        String responseBody = EntityUtils.toString(response.getEntity());

        Log.i("responseBody", responseBody);

        return responseBody;
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Internal Error
    return "ierror";
}

1 个答案:

答案 0 :(得分:0)

如果您正在寻找一种在 iOS 中对网址进行网址编码的方法, 您可以使用stringByAddingPercentEscapesUsingEncoding:的{​​{1}}方法。

在文档NSString Class Reference中查看更多内容。