0

In Java 1.4, I am trying to make an connection to a URL, but since I want to configure a timeout, I am using Apache's httpclient instead of the old school URLConnection.openConnection();

So I have the following:

    HttpConnection conn = null;
    SimpleHttpConnectionManager httpMgr = new SimpleHttpConnectionManager(true);
    HostConfiguration hostConf = new HostConfiguration();
    hostConf.setHost(new HttpHost("http://www.google.com"));
    conn = httpMgr.getConnectionWithTimeout(hostConf, 30);
    conn.open();

But seems like everytime I try to open a connection, I would get a java.net.UnknownHostException: http://www.google.com, even to google.com.

Did I do something wrong..?

phychem
  • 25
  • 5

1 Answers1

2

I think protocol (http://) is what breaks it. Try using "www.google.com" as a host name. HTTP CLient tutorial is here.

mazaneicha
  • 8,794
  • 4
  • 33
  • 52
  • Oh great now it works! But somehow, after the connection gets opened, it fails to retrieve the input stream conn.getResponseInputstream() – phychem Dec 07 '12 at 06:04