You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Allistair Crossley <a....@obvious.uk.com> on 2002/04/24 12:05:47 UTC

HttpClient throwing UnknownHostException

I have just started to use HttpClient. The code compiles fine and I have
used the test cases as guidance.

However, my code throws an UnknownHostException and I am not sure why. I
have tested this with the jakarta host and port 80 but it does not work. I
am on a LAN so there is a connection.

I attach my code here

import java.io.*;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;


public class HTTPPoster2 extends Thread
{
	public HTTPPoster2()
	{
		start();
	}

	public void run()
	{
		System.out.println("HTTPPoster Started");

		try { Thread.sleep(2000); } catch(InterruptedException iE) { ; }

		try
		{
			GetMethod httpGet = new GetMethod();

			HttpClient httpClient = new HttpClient();
			httpClient.startSession("http://jakarta.apache.org", 80);
			httpClient.executeMethod(httpGet);
        	httpClient.endSession();

        	System.out.println("Response: " +
httpGet.getResponseBodyAsString());

		}
		catch(IOException ioE)
		{
			System.out.println("HTTPPoster IOException: " + ioE);
		}
		catch(HttpException ioE)
		{
			System.out.println("HTTPPoster HttpException: " + ioE);
		}
		catch(IllegalStateException isE)
		{
			System.out.println("HTTPPoster IllegalStateException: " + isE);
		}

		System.out.println("HTTPPoster Ended");
	}
}


Allistair Crossley
Lead Technical Developer
Obvious Solutions (Global) Ltd.
“Delivering the vision for a mobile lifestyle”

www.obvioussolutions.co.uk

(m) +44 (0) 7884 056 274
(w) +44 (0) 20 8451 9352
(f) +44 (0) 20 8537 5236

/******************************************/

This is an email from Obvious Solutions (Global) Ltd.
The contents of this email are confidential to the ordinary
user of the email address to which it was addressed. No-one
else may copy or forward all or any of it in any form.
If you receive this email in error, we should be obliged if
you would telephone our postmaster on +44 (0)208 357 8352
or  email postmaster@obvious.uk.com. Thank you.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>