HttpGet httpGet = new HttpGet("http://stackoverflow.com/");
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000)
.setConnectionRequestTimeout(1000)
.setSocketTimeout(5000).build();
httpGet.setConfig(requestConfig);
CloseableHttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();//得到請求回來的數(shù)據(jù)
setConnectTimeout:設(shè)置連接超時時間,單位毫秒。
setConnectionRequestTimeout:設(shè)置從connect Manager獲取Connection 超時時間,單位毫秒。這個屬性是新加的屬性,因為目前版本是可以共享連接池的。
setSocketTimeout:請求獲取數(shù)據(jù)的超時時間,單位毫秒。 如果訪問一個接口,多少時間內(nèi)無法返回數(shù)據(jù),就直接放棄此次調(diào)用。文章來源地址http://www.zghlxwxcb.cn/news/detail-505181.html
文章來源:http://www.zghlxwxcb.cn/news/detail-505181.html
到了這里,關(guān)于【JAVA】設(shè)置http超時時間的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!