Java httpclient problem: the server failed to respond with a valid HTTP Response

Source: Internet
Author: User

Caused by: org. Apache. http. protocolexception: the server failed to respond with a valid HTTP Response

This error occurs when I used Java's httpclient before my account was recorded yesterday. This error generally indicates that the server does not provide the correct HTTP response. this error may be caused by the use of the same httpclient persistent connection/persistence connection, and then the use of this httpclient for other network requests.

If the http get request is used (other requests are handled similarly ). The solution is:

// Codehttpget = new httpget (urlwithparam); httpresponse response; try {response = httpclient.exe cute (get); // read response entity // do something !!! } Catch (exception e) {e. printstacktrace (); throw new runtimeexception (E);} finally {Get. Abort (); If (response! = NULL) {entityutils. consumequietly (response. getentity ());}}

Get all the content before abort. Disable the connection. At the same time, the entity is also killed. The key to solving the problem here is get. Abort (). If entity is not disabled, the problem is: httpclient is stuck. Click here for details

Of course, there is another solution: regardless of the new httpclient. This method is not recommended (consumes a lot of resources ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.