Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android httprequest java.net.UnknownHostException

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

like image 533
Alex Poke Avatar asked Aug 24 '10 15:08

Alex Poke


People also ask

What is Java net UnknownHostException?

UnknownHostException indicates that the IP address of a hostname could not be determined. It can happen because of a typo in the hostname: String hostname = "http://locaihost"; URL url = new URL(hostname); HttpURLConnection con = (HttpURLConnection) url. openConnection(); con.

What is UnknownHostException In android?

Thrown to indicate that the IP address of a host could not be determined.


1 Answers

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

like image 186
Yoni Samlan Avatar answered Sep 22 '22 17:09

Yoni Samlan