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

