Error when I use HttpUrlConnection to download info from a specific url
<p>I am writing an app on android 3.1, and I am using galaxy tab 10.1 to test my app.</p>

<p>I wrote a function called OpenHttpConnection() in order to get some information from a specific website. And the code snippets is:</p>

<pre><code>private InputStream OpenHttpConnection(String urlString) throws IOException {
    InputStream in = null;
    int response = -1;

    URL url = new URL(urlString);
    String host = url.getHost();
    InetAddress address = InetAddress.getByName(host);
    String ip = address.getHostAddress();
    Toast.makeText(this, "ip address: " + ip.toString(), Toast.LENGTH_SHORT).show();

    try {
        HttpURLConnection httpConn = (HttpURLConnection)url.openConnection();
        httpConn.setAllowUserInteraction(false);
        httpConn.setInstanceFollowRedirects(true);
        httpConn.setConnectTimeout(5 * 1000);
        httpConn.setRequestMethod("GET");
        Toast.makeText(this, "prepare for connecting", Toast.LENGTH_SHORT).show();
        httpConn.connect();
        Toast.makeText(this, "connecting established", Toast.LENGTH_SHORT).show();
        response = httpConn.getResponseCode();
        if (response == HttpURLConnection.HTTP_OK) {
            in = httpConn.getInputStream();
        }
    } catch (Exception ex) {
        throw new IOException("Error connecting");
    }
    return in;
}
</code></pre>

<p>Error happens when the line "httpConn.connect()" is being executed. I googled this question and found many people got this problem, and they said it was a matter of DNS. Then I tried to get the ip address of this url, I failed, somethings was wrong. I have already add the permission to the AndroidManifest.xml like this:</p>

<pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
</code></pre>

<p>Did I miss some permission?</p>

<p>I can use my tablet to access the internet successfully and the DNS of my tablet is as same as my pc, and they are in one LAN.</p>

<p>I am very confused, and can u help solve it?</p>

<p>;)thx</p>
