---
title: "HttpClient 4 和 HttpClient 3 设置超时 "
author: "greenwen"
date: "2013-01-09T15:44:41Z"
tags: []
categories: ["编程语言"]
slug: "httpclient-4-httpclient-3"
draft: false
lastmod: "2013-01-09T15:44:41Z"
id: 1766891
url: "https://superivan.iteye.com/blog/1766891"
---

HttpClient 4：
连接超时：


```java
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,60000); 
// 或者 
HttpConnectionParams.setConnectionTimeout(params, 6000); 
```

读取超时：


```java
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,60000); 
// 或者 
HttpConnectionParams.setSoTimeout(params, 60000); 
```


HttpClient 3：
连接超时：


```java
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(60000); 
```


读取超时：

```java

httpClient.getHttpConnectionManager().getParams().setSoTimeout(60000); 
```