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..?

3
  • Unrelated, but why java 6 will be EOL in February. Commented Dec 7, 2012 at 3:56
  • unfortunately, I'm stuck with Java 1.4 Commented Dec 7, 2012 at 3:57
  • Are you trying to run the code behind a firewall? If so, your question is the same as stackoverflow.com/q/6384135/130224 Commented Dec 7, 2012 at 4:06

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Oh great now it works! But somehow, after the connection gets opened, it fails to retrieve the input stream conn.getResponseInputstream()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.