hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Song Chang <cs...@yahoo.com>
Subject Connection Reset problem
Date Wed, 22 Mar 2006 15:32:32 GMT
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
Source)
        at java.io.BufferedInputStream.fill(Unknown
Source)
        at java.io.BufferedInputStream.read(Unknown
Source)
        at
org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77)
        at
org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105)
        at
org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115)
        at
org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832)
        at
org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
        at
org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java
:397)
        at
org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:17
0)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
        at
org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)
        at
HttpClientTutorial.main(HttpClientTutorial.java:24)
 

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import
org.apache.commons.httpclient.params.HttpMethodParams;

import java.io.*;

public class HttpClientTutorial {
  
  private static String url =
"http://www.apache.org/";

  public static void main(String[] args) {
    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    GetMethod method = new GetMethod(url);
    
    // Provide custom retry handler is necessary
   
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,

    		new DefaultHttpMethodRetryHandler(3, false));

    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: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message