Thanks, Roland. After some googling, I tried the following code which explicitly set http header. It works for those sites which didn't work for me before. Could it be an issue of user-agent? I am using HttpClient 1.3. I tried this with both java 1.4 and 1.5 and on both Linux and Windows.
I tried without retry-handling, it didn't work either. It has to do with the headers. The code was simply copied from tutorial site, which makes me to think it has to work for others at least when hitting http://www.apache.org, as it is hard coded in the example. method.setUseExpectHeader( false ); method.setFollowRedirects(true); method.setStrictMode(false); method.setRequestHeader(new Header("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)" ) ); method.setRequestHeader( new Header( "accept", "*/*" ) ); method.setRequestHeader( new Header( "accept-language", "en-us" ) ); method.setRequestHeader( new Header( "accept-encoding", "gzip, deflate" ) ); method.setRequestHeader( new Header( "connection", "Keep-Alive" ) ); method.setRequestHeader( new Header( "cache-control", "no-cache" ) ); --- Roland Weber <[EMAIL PROTECTED]> wrote: > Hi, > > Song Chang wrote: > > Hi, I tried the following program. Everytime I get > the > > following exception when hitting www.apache.org. > > However if I change to www.sun.com, I get the > > response. It is really weird it works on some > sites, > > but not others. For example, www.ibm.com get the > same > > error. While www.nyu.edu works. I am totally > confused > > with this. I tried both java 1.4.2 and java 1.5. > Your > > help is really appreciated. > > > > Fatal transport error: Connection reset > > java.net.SocketException: Connection reset > > at java.net.SocketInputStream.read(Unknown > > > // Provide custom retry handler is necessary > > > > > method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, > > > > new DefaultHttpMethodRetryHandler(3, > false)); > > Why do you need a retry handler? Have you tried > without? > I suspect some problem related to connection re-use, > and > since you're sending only one request that probably > has > to do with retry handling. > > Which version of HttpClient are you using? Please > post > wire logs for a host that is working and one that > fails: > http://jakarta.apache.org/commons/httpclient/logging.html > > cheers, > Roland > > > > > > try { > > // Execute the method. > > int statusCode = > client.executeMethod(method); > > > > if (statusCode != HttpStatus.SC_OK) { > > System.err.println("Method failed: " + > > method.getStatusLine()); > > } > > > > // Read the response body. > > byte[] responseBody = > method.getResponseBody(); > > > > // Deal with the response. > > // Use caution: ensure correct character > > encoding and is not binary data > > System.out.println(new > String(responseBody)); > > > > } catch (HttpException e) { > > System.err.println("Fatal protocol > violation: " > > + e.getMessage()); > > e.printStackTrace(); > > } catch (IOException e) { > > System.err.println("Fatal transport error: " > + > > e.getMessage()); > > e.printStackTrace(); > > } finally { > > // Release the connection. > > method.releaseConnection(); > > } > > } > > } > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: > [EMAIL PROTECTED] > > For additional commands, e-mail: > [EMAIL PROTECTED] > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: > [EMAIL PROTECTED] > For additional commands, e-mail: > [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
