使用Httppost而不使用urlencode参数的Android帖子请求

时间:2013-08-19 02:26:03

标签: java android http-post

这是我的代码......是否可以删除urlencode? 我想传递post参数而不用urlencode它们。 感谢

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

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情

HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
BasicHttpEntity filter = new BasicHttpEntity();
filter.setContent(new ByteArrayInputStream("Filter=id :EQUALS: 12345 :AND: stringdata :EQUALS: hi".getBytes("UTF-8")));
httppost.setEntity(filter);

由于