在使用org.apache.http.client.methods.HttpPost 发送请求时,需要对这三个属性进行设定。
使用其下工具类RequestConfig:
RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout(100000) //①
.setConnectTimeout(100000) //②
.setSocketTimeout(100000) //③
.build();
①httpclient使用连接池来管理连接,这个时间就是从连接池获取连接的超时时间,如DB连接池。
②连接建立时间,三次握手完成时间,常见异常:java.net.ConnectException: Connection refused: .......。
③已经成功建立了连接,数据传输时包传输最大时间间隔,如服务器传输数据给客户端超时,常见异常:java.net.SocketTimeoutException: Read timed out....。
相关阅读
发表评论