HTTPClient.executeMethod(getmethod) is throwing java.net.UnknownHostExcepti

Hi all,

I am trying to execute below code,

public static void main(String[] args){

HttpClient client = new HttpClient();

// an example only... replace this with your site

GetMethod method = new GetMethod("http://www.google.co.in/");

try {

// get the response code, hopefully "successful" (SC_OK, or 200)

int response = client.executeMethod(method);

if (response == HttpStatus.SC_OK) {

String result = method.getResponseBodyAsString();

// this is the document returned by the response

System.out.println(result);

Cookie[] cookies = client.getState().getCookies();

System.out.println(Arrays.toString(cookies));

} else {

System.err.println("Response code: " + method.getStatusLine());

}

} catch (IOException e) {

e.printStackTrace();

}

}

And when I run this, it throws me below error:

java.net.UnknownHostException: www.google.co.in

at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)

at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

at java.net.Socket.connect(Socket.java:516)

at java.net.Socket.connect(Socket.java:466)

at java.net.Socket.<init>(Socket.java:366)

at java.net.Socket.<init>(Socket.java:239)

at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:79)

at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:121)

at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:706)

at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:386)

at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)

at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)

at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324)

at xmlstreamvalidator.URLValidator.main(URLValidator.java:40)

Please help me in understanding why am I getting this error and how to resolve it.

Thanks in advance,

Mithun K

[2233 byte] By [MithunKa] at [2007-11-27 7:16:31]
# 1
Sorry, I forgot to mention that I am using org.apache.commons.httpclient HttpClient package
MithunKa at 2007-7-12 19:05:32 > top of Java-index,Core,Core APIs...
# 2

> java.net.UnknownHostException: www.google.co.in

> at

Assuming that you are using the Apache API correctly in terms of what you asked from it this error means you have a non Java related DNS problem.

Run an nslookup on the computer you are running this program on with this host.

cotton.ma at 2007-7-12 19:05:32 > top of Java-index,Core,Core APIs...