开发者

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");
   开发者_Python百科 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?


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜