tags:

views:

70

answers:

3

I'v got the following piece of code:

try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("http://www.flashstall.com/json.txt");
    HttpResponse httpResponse = httpClient.execute(httpPost);
} catch (Exception e) {
    Log.e("m40", "Error in http connection " + e.toString());
}

When I run it it logs "Error in http connection java.net.UnkownHostException: www.flashstall.com".

What am I doing wrong?

A: 

From my understanding, you can't have json.txt as a part of the URI.

Abdo
Why, is it because of the .txt extension?
Emanuil
json.txt is a file. Your webserver won't "understand" your call.Check what adrian wrote below =)
Abdo
A: 

For a basic example convert your json.txt file into a php file and just echo your data. Then you'll be able to use it as:

HttpPost httpPost = new HttpPost("http://www.flashstall.com/json.php");

For a more detailed example check here.

Adrian Faciu
Changed the url to http://www.flashstall.com/json.php. Still get the error.
Emanuil
+1  A: 

If I read your question correctly, you have a network error. The UnknownHostException is thrown when the hostname cannot be resolved. In your case its: www.flashstall.com.

Looks like you cannot access the site www.flashstall.com because perhaps you are not connected to the internet.

How to verify:

Open your adb shell $>adb shell and try to ping www.flashstall.com.

naikus