HTTP requests with HttpClient too slow?

半世苍凉 提交于 2019-12-04 11:21:29
MAJS

Try using this configuration

HttpClient httpclient = new DefaultHttpClient();
HttpParams httpParameters = httpclient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(httpParameters, WAIT_RESPONSE_TIMEOUT);
HttpConnectionParams.setTcpNoDelay(httpParameters, true);

This is the javadoc about setTcpNoDelay:

public static void setTcpNoDelay (HttpParams params, boolean value)

Since: API Level 1

Determines whether Nagle's algorithm is to be used. The Nagle's algorithm tries to conserve bandwidth by minimizing the number of segments that are sent. When applications wish to decrease network latency and increase performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY). Data will be sent earlier, at the cost of an increase in bandwidth consumption.

Parameters

value true if the Nagle's algorithm is to NOT be used (that is enable TCP_NODELAY), false otherwise.

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