Emanuil Rusev
Emanuil Rusev

Reputation: 35235

Connecting to a web server over HTTP, code snippet

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?

Upvotes: 1

Views: 629

Answers (3)

naikus
naikus

Reputation: 24472

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.

Upvotes: 1

Adrian Fâciu
Adrian Fâciu

Reputation: 12552

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.

Upvotes: 0

Abdo
Abdo

Reputation: 14051

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

Upvotes: 0

Related Questions