Re: HttpURLConnection timeout?
- From: "Adam P. Jenkins" <news@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 12 Apr 2005 21:59:30 -0400
Dave Ockwell-Jenner wrote:
Jack wrote:
Hi,
Is it possible to set a timeout when opening a connection to an HttpURLConnection?
For example, is it possible to make the connection call and limit it to 5 seconds before a response is generated?
That is, I don't want to have to wait for the "default" timeout.
[snip]
You can't do this using Sun's classes unless you use a "private" property setting. Unfortunately, the setting is not guaranteed to remain the same (or remain at all).
I've just been working on a similar task and used the Commons-HTTPClient[1] from Apache. It allows you to specify both a connection timeout and also a timeout when reading the response. It works superbly!
[1] http://jakarta.apache.org/commons/httpclient/
Actually Sun has added this in Java 1.5. See the java.net.URLConnection setConnectionTimeout() and setReadTimeout() methods. If you need to use an earlier version of Java then the Jakarta HTTPClient package works great.
.
- Prev by Date: StandardHost[localhost]: MAPPING configuration error for request URI /favicon.ico
- Next by Date: how to use javascript functions in struts html:form
- Previous by thread: StandardHost[localhost]: MAPPING configuration error for request URI /favicon.ico
- Next by thread: how to use javascript functions in struts html:form
- Index(es):
Relevant Pages
|
|