1

嗨 :) 我遇到了一个简单的问题,但很烦人。我正在尝试使用 HttpPost 类发送 http post 请求

这是返回 InputStream 的方法的一部分:

           HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url+path); 
        ArrayList<NameValuePair> paramsList = new ArrayList<NameValuePair>();
        paramsList.add(new BasicNameValuePair("key1", value1));
        paramsList.add(new BasicNameValuePair("key2", value2));
        paramsList.add(new BasicNameValuePair("key3", value3));

        httpPost.setEntity(new UrlEncodedFormEntity(paramsList));

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        InputStream is = httpEntity.getContent();
        return is;

但问题出在服务器上,因为服务器“认为”我发送的是 GET 请求而不是 POST。问题是:错误在哪里?我在其他应用程序中使用类似的代码部分,它工作正常。

干杯。:)

4

1 回答 1

0

请试试

httpPost.setEntity(new UrlEncodedFormEntity(paramsList, HTTP.UTF_8));

代替

httpPost.setEntity(new UrlEncodedFormEntity(paramsList));
于 2012-06-04T13:33:06.517 回答