2014-02-27 77 views
0

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

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"; 
} 

回答

0

如果你正在寻找一种方式来编码的URL字符串中的iOS, 可以使用的NSStringstringByAddingPercentEscapesUsingEncoding:方法。

查看更多文档NSString Class Reference