开发者

Connecting to a web server over HTTP, code snippet

开发者 https://www.devze.com 2023-01-02 19:10 出处:网络
I\'v got the following piece of code: try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(\"http://www.flashstall.com/json.txt\");

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

精彩评论

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

关注公众号