hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Puneet Lakhina" <puneet.lakh...@gmail.com>
Subject Tutorial possible error
Date Sun, 16 Jul 2006 19:51:30 GMT
Hi,
I am really new to this api. I went through the tutorial and tried doing the
very basic thing. Just getting the reponse based on a http request.

HttpClient client  = new HttpClient();
GetMethod method = new GetMethod("www.google.com");
try {
client.executeMethod(method);
System.out.println(new String(method.getResponseBody());
}catch(Exception e) {
e.printStackTrace();
}

But this throws an exception
java.lang.IllegalArgumentException: host parameter is null
        at org.apache.commons.httpclient.HttpConnection.<init>(
HttpConnection.java:205)
        at org.apache.commons.httpclient.HttpConnection.<init>(
HttpConnection.java:154)
        at
org.apache.commons.httpclient.SimpleHttpConnectionManager.getConnectionWithTimeout
(SimpleHttpConnectionManager.java:149)
        at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(
HttpMethodDirector.java:152)
        at org.apache.commons.httpclient.HttpClient.executeMethod(
HttpClient.java:396)
        at org.apache.commons.httpclient.HttpClient.executeMethod(
HttpClient.java:324)


While browsing through the examples i found the following thig used..

client.getHostConfiguration().setHost("www.google.com");

so i tried this and then it worked fine.
I am using jdk 1.5
httpclient version 3.0.1
logging version 1.1
codec version 1.3

is there something wrong with the way im doing things??
because thats the way its suggested in the url, sans the retry code.

My redone code looks like this

HttpClient client  = new HttpClient();
client.getHostConfiguration().setHost("www.google.com");
GetMethod method = new GetMethod("www.google.com");
try {
client.executeMethod(method);
System.out.println(new String(method.getResponseBody());
}catch(Exception e) {
e.printStackTrace();
}

Thanks
-- 
Puneet

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