2012-06-04 82 views
1

嗨:)我有一个简单的问题,但非常讨厌。 我试图使用HttpPost类HttpPost - http请求方法的类型

这是返回的InputStream方法的一部分发送HTTP POST请求:

  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。问题是:哪里出错?我在其他应用程序中使用类似的代码部分,它工作正常。

干杯。 :)

+0

也许你需要改变你的电话就搞定了。你有什么样的服务?它是PHP? PHP明确区分post和get,如果它期望GET的参数,它将无法从POST获取它。 – Th0rndike

+0

webservice正在等待POST请求,没有机会使用GET发送参数:( –

+2

是什么让你认为服务器看到GET请求? –

回答

0

请尝试

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

,而不是

httpPost.setEntity(new UrlEncodedFormEntity(paramsList)); 
+0

它不工作:( –

+0

请分享你的代码.. – Nikhil

+0

这是所有,我得到了我的方法,区别仅在参数。使用BufferedReader和readLine()方法。 –