0

I answered the following question :

not getting response response = httpclient.execute(request);

See my answer there.Then I got a comment on my answer from Peterdk

as :

The response is not a HtppResponse but a String. Or how do you get it to be a HttpResponse? Does this depend on the ResponseHandler?

Now i have a doubt "Is HttpResponse a String ?"

Please help me clear my this doubt and explain me what was wrong in my concept.

Community
  • 1
  • 1
Shruti
  • 1
  • 13
  • 55
  • 95

1 Answers1

0

That comment on your answer makes no sense at all to me. I also have no idea why you were down-voted, though really I don't think the question was worded well enough to be properly answered, but if you're really in doubt with something like this you can think through it logically by checking the docs.

Short answer:

HttpResponse is not a String.

Long answer:

The documentation for HttpClient.execute(string) shows this as the method signature:

public abstract HttpResponse execute (HttpUriRequest request)

So clearly execute returns you an HttpResponse.

Now if you go to the docs for HttpResponse you find that HttpResponse is an interface and includes methods such as the method you used in your answer: getStatusLine(). Immediately you know that an interface isn't a String, so HttpResponse isn't a String, but in case you might think it's the other way and maybe String implements HttpResponse, it should be fairly obvious that String doesn't have a method called getStatusLine() and that it'd be ridiculous for something as generic as a String to implement an interface to do with HTTP. If you really want to be sure, you can check the docs again and see that String doesn't have getStatusLine() and doesn't implement the interface HttpResponse.

kabuko
  • 36,028
  • 10
  • 80
  • 93
  • The documentation also shows that `execute` has also a generic method, that depends on the `responseHandler`. `public abstract T execute` So both answers are valid. If you supply a responsehandler, it gives you a different kind of response. – Peterdk Dec 03 '11 at 14:44
  • That method signature: `public abstract T execute (HttpUriRequest request, ResponseHandler extends T> responseHandler)` – Peterdk Dec 03 '11 at 15:03
  • Ahhh... totally missed that Peterdk, thanks for clarifying. That said, the original question mentioned (as well as Shruti's response) happened to use the overload that only returned an HttpResponse. – kabuko Dec 04 '11 at 08:19