Android HttpClient : NetworkOnMainThreadException
<p>I have some code below:</p>

<pre><code>protected void testConnection(String url) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    ResponseHandler&lt;String&gt; responsehandler = new BasicResponseHandler();

    try {
        String connection = httpclient.execute(httpget, responsehandler);
        Toast.makeText(getBaseContext(), R.string.connection_succeed, Toast.LENGTH_SHORT).show();
        view_result.setText(connection);
    } catch(IOException e) {
        Toast.makeText(getBaseContext(), R.string.connection_failed, Toast.LENGTH_SHORT).show();
    }
    httpclient.getConnectionManager().shutdown();
}
</code></pre>

<p>and add a permission in Menifest:</p>

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

<p>But it goes an exception:
NetworkOnMainThreadException, 
How can i do?</p>
