在android中没有获得http post请求的响应体?

Sum*_*man 5 android

没有得到android中的http post请求的响应体.
我提到了名称值对中的用户ID,密码以及放入httppost请求

postrequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
Run Code Online (Sandbox Code Playgroud)

但在执行时我得到的响应为SC_OK(200),但响应体是null.

还有一个问题是,如果我使用setHeader()函数在HTTPGet或HTTPPost的请求中指定头,我将获得BAD REQUEST(404)响应.

请帮我解决上述问题.

谢谢和问候,
SSuman185

Ven*_*nky 0

嗨,朋友,请尝试这种方式来获取服务器的响应。

其中给定链接是您要发布请求的链接。

String link2 = "http://184.106.227.45/quaddeals/university-of-illinois/androids_deals/user_card_list.json";

DefaultHttpClient hc1 = new DefaultHttpClient();

ResponseHandler<String> res1 = new BasicResponseHandler();

HttpPost postMethod1 = new HttpPost(link2);

List<NameValuePair> nameValuePairs1 = new ArrayList<NameValuePair>(1);

nameValuePairs1.add(new BasicNameValuePair("user_id",account_userId));

postMethod1.setEntity(new UrlEncodedFormEntity(nameValuePairs1));

String response1 = hc1.execute(postMethod1, res1);
Run Code Online (Sandbox Code Playgroud)