hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uwcssa <uwc...@gmail.com>
Subject HttpClient does not capture all strings in Response
Date Sun, 20 Jun 2010 19:51:49 GMT
The story begins here:  from the following URL, if you enter people's name,
it will return either the person's info, or return "There were no matches to
your search criteria. Please try again."

   http://watiam.uwaterloo.ca/search/search.jsp

I tried using httpclient, as well as httpcore.   The result is the same,
neither such info is included in the result.  The result is an HTML page
with everything as shown from a browser, WITHOUT the  sensitive
information.


I am attaching my script here,  anybody knows what special handling I am
missing when dealing with the response part?



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://watiam.uwaterloo.ca/search/search.jsp
";

  public static void main(String[] args) {


    // Create an instance of HttpClient.
    HttpClient client = new HttpClient();

    // Create a method instance.
    PostMethod method = new PostMethod(url);

    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
     new DefaultHttpMethodRetryHandler(3, false));

    NameValuePair[] data = {
          new NameValuePair("givenname","James"),
  new NameValuePair("surname","David")
        };
     method.setRequestBody(data);
     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));

      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();
    }
  }
}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message