Is HttpResponse String?

北战南征 提交于 2019-12-12 02:34:49

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8365741/is-httpresponse-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!