fix java.net.SocketTimeoutException: Read timed out

前端 未结 2 1201
迷失自我
迷失自我 2020-12-25 15:21

I have a RESTful server which takes an http POST input from client to vote up songs on server. I have used Apache HTTPClient for client.

public boolean vote(         


        
相关标签:
2条回答
  • 2020-12-25 15:50

    Here are few pointers/suggestions for investigation

    1. I see that every time you vote, you call vote method which creates a fresh HTTP connection.
    2. This might be a problem. I would suggest to use a single HttpClient instance to post to the server. This way it wont create too many connections from the client side.
    3. At the end of everything, HttpClient needs to be shut and hence call httpclient.getConnectionManager().shutdown(); to release the resources used by the connections.
    0 讨论(0)
  • 2020-12-25 15:54

    I don't think it's enough merely to get the response. I think you need to read it (get the entity and read it via EntityUtils.consume()).

    e.g. (from the doc)

         System.out.println("<< Response: " + response.getStatusLine());
         System.out.println(EntityUtils.toString(response.getEntity()));
    
    0 讨论(0)
提交回复
热议问题