Hello,

I am using HttpClient from CVS HEAD from exactly 1 month ago (May 6,
2004).  Although I set the time-out to 5 seconds, I noticed that it
does not always work, and because of that my application often hangs
indefinitely.

Perhaps I'm not using the API correctly.
Here are the relevant portions of my code:
(HttpResponse is my class - a simple 'struct', nothing else)


HttpClientParams clientParams = new HttpClientParams();
clientParams.setParameter(HttpClientParams.USER_AGENT, "xxx");

_client = new HttpClient(clientParams);
_client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

GetMethod method = new GetMethod(urlString);
method.setFollowRedirects(false);

String responseBody = null;
try {
    _client.executeMethod(method);
    responseBody = method.getResponseBodyAsString();
} catch (HttpException he) {
    System.err.println("Http error connecting to '" + url + "'");
    method.releaseConnection();
    method.recycle();
    return new HttpResponse(-1, -1, null, null);
} catch (IOException ioe) {
    System.err.println("Unable to connect to '" + url + "'");
    method.releaseConnection();
    method.recycle();
    return new HttpResponse(-1, -1, null, null);
}

int statusCode = method.getStatusCode();
long sizeBytes = method.getResponseContentLength();
String charSet = method.getResponseCharSet();
String lang    = null;

// clean up the connection resources
method.releaseConnection();
method.recycle();

return new HttpResponse(statusCode, sizeBytes, null, charSet);



Am I forgetting to call something that will ensure that no request ever
hangs forever?

Thank you,
Otis


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to