我得到的回答是这样的:
HttpResponse response = httpclient.execute(httpget);
response.getStatusLine().toString());
在这种情况下,回复是:
HTTP/1.1 500 invalid user credentials
我是否只收到消息,没有代码?
**invalid user credentials**
答案 0 :(得分:1)
试试这个:
HttpResponse response = httpclient.execute(httpget);
StatusLine statusLine = response.getStatusLine();
String messageOnly = statusLine.getReasonPhrase();
int codeOnly = statusLine.getStatusCode();
答案 1 :(得分:1)
简单,这样做
String responseStr = EntityUtils.toString(response.getEntity());
这会有效!
答案 2 :(得分:0)
你可以简单地得到这样的信息
String message = response.getStatusLine().toString().substring(12);
答案 3 :(得分:0)
使用HttpURLConnection
的{{1}}请参阅this
答案 4 :(得分:0)
试试这个:
HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
然后将此输入流转换为字符串......
答案 5 :(得分:0)
使用StatusLine接口的getReasonPhrase()方法。 e.g。
HttpResponse response = httpclient.execute(httpget);
StatusLine statusLine = response.getStatusLine();
statusLine.getReasonPhrase()