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 ).