Harry
Harry

Reputation: 13329

Getting Android HttpResponse message without the response code

I'm getting the response like this:

HttpResponse response = httpclient.execute(httpget);
response.getStatusLine().toString());

In this case the response is:

HTTP/1.1 500 invalid user credentials

Ho do I get the message only, without the code?

**invalid user credentials**

Upvotes: 0

Views: 1543

Answers (6)

Ajit
Ajit

Reputation: 967

Use getReasonPhrase() method of StatusLine interface. e.g.

HttpResponse response = httpclient.execute(httpget);
StatusLine statusLine = response.getStatusLine();
 statusLine.getReasonPhrase()

Upvotes: 0

nithinreddy
nithinreddy

Reputation: 6197

Simple, do this

String responseStr = EntityUtils.toString(response.getEntity());

This will work!

Upvotes: 1

faceman
faceman

Reputation: 1328

Try this:

HttpResponse response = httpclient.execute(httpget);
StatusLine statusLine = response.getStatusLine();

String messageOnly = statusLine.getReasonPhrase();
int codeOnly = statusLine.getStatusCode();

Upvotes: 1

Anand
Anand

Reputation: 2885

try this :

HttpResponse response = client.execute(httpGet);
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent(); 

and then convert this input stream into string......

Upvotes: 0

Shafi
Shafi

Reputation: 1368

Use HttpURLConnection's getResponseMessage() See this

Upvotes: 0

Gyonder
Gyonder

Reputation: 3756

You could simply get the message like this

         String message = response.getStatusLine().toString().substring(12);

Upvotes: 0

Related Questions