【问题标题】:Android post request using Httppost without urlencode parameter使用没有 urlencode 参数的 Httppost 的 Android 发布请求
【发布时间】:2013-08-19 02:26:02
【问题描述】:

这是我的代码...可以删除 urlencode 吗? 我想在没有 urlencode 的情况下传递 post 参数。 谢谢

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

【问题讨论】:

    标签: java android http-post


    【解决方案1】:

    你可以试试这样的

    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);
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2014-12-23
      • 2019-03-18
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多