views:

220

answers:

2

Hi,

I want to make a http request with android.

is use this:

void testHTTP()
 {
  HttpClient httpClient = new DefaultHttpClient();

  HttpUriRequest request = new HttpPost("http://www.google.com");

  try {
   HttpResponse response = httpClient.execute(request);

   //System.out.println("response protocol version: " + response.getProtocolVersion());
  } catch (ClientProtocolException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }

I have the internet permission set in my manifest file.

I keep getting java.net.UnknownHostException: www.google.com

My final purpose ios to be able to invoke a web service. So, I initially tried the ksoap2 library and the proper url and got the same result.

I suspect I have some bad setting either in my app or in my emulator.

can you give me some pointers on where to look?

it would also bee useful a working example of something similar. then i could check and if the problem persists i would know that is my development setup at fault.

btw, i am using mac snow leopard with eclipse and android 2.2 as a setup

thanks

regards

A: 

Check the emulator log messages. There's a good chance you just aren't asking for the INTERNET permission in your app manifest.

Yoni Samlan
this is what i am using:...<uses-permission android:name="android.permission.INTERNET"></uses-permission></manifest>
Alex Poke
A: 

I've had problems with the emulator where the network icon shows that I have no service, and I can't connect to the Internet. Usually, restarting the emulator fixed it. Once, I had to create a new emulator device.

Do check for clues in the emulator/device logs. You can view them in Eclipse using the LogCat view in the DDMS perspective.

BenTobin
restarting the emulator fixed the issue. i should have checked the browser to see if it works. it wasn't.thanks
Alex Poke