HttpURLConnection connect() Exception on 4.0 & 4.1 but not on 2.3.3
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13429430/android-app-doesnt-work-on-android-4">Android app doesn’t work on Android 4</a>  </p>
</blockquote>



<p>I'm working on an android app. trying to find the solution for hours. My app works fine with the database and server when I'm running emulator 2.3.3 but no on 4.0 or 4.1 or any version above 2.3.3. the app throws an exception in this method: the exception happens when trying to do <code>connection.connect();</code> please help.</p>

<pre><code>public void sendOutputLine(URL url, String outputLine) {
    try {
        connection = (HttpURLConnection) url.openConnection();
        Log.d(LogInActivity.DEBUG_TAG, "1");
        connection.setDoInput(true);
        Log.d(LogInActivity.DEBUG_TAG, "2");    
        connection.setDoOutput(true);
        Log.d(LogInActivity.DEBUG_TAG, "3");    
        connection.setRequestMethod("POST");
        Log.d(LogInActivity.DEBUG_TAG, "4");    
        connection.setFixedLengthStreamingMode(outputLine.length());
        Log.d(LogInActivity.DEBUG_TAG, "5");    
        connection.connect();
        Log.d(LogInActivity.DEBUG_TAG, "6");    
        out = connection.getOutputStream();
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
        pw.print(outputLine);
        pw.flush();
        out.close();
    } catch (SocketTimeoutException e) {
        Log.d(LogInActivity.DEBUG_TAG,
                "SocketTimeoutException sendOutputLine(): " + e.getMessage());          
    } catch (ProtocolException e) {
        Log.d(LogInActivity.DEBUG_TAG,
                "Protocol exception sendOutputLine(): " + e.getMessage());
    } catch (IOException e) {
        Log.d(LogInActivity.DEBUG_TAG, "IO exception sendOutputLine(): "
                + e.getMessage());
    } catch (Exception e) {
        Log.d(LogInActivity.DEBUG_TAG,
                "Exception bommed client: " + e.getMessage());  
    }
}
</code></pre>

<p>Logcat:</p>

<pre><code>11-17 13:19:11.710: D/SocialFamilyTree(847): outputLint: Login%a@a%57963634
11-17 13:19:11.710: D/SocialFamilyTree(847): 1
11-17 13:19:11.710: D/SocialFamilyTree(847): 2
11-17 13:19:11.710: D/SocialFamilyTree(847): 3
11-17 13:19:11.710: D/SocialFamilyTree(847): 4
11-17 13:19:11.710: D/SocialFamilyTree(847): 5
11-17 13:19:11.740: D/SocialFamilyTree(847): Exception bommed client: null
</code></pre>

<p><strong>EDIT</strong>:
I see, so I need to use <code>AsyncTask</code></p>

<p>How do I use the <code>AsyncTask</code> for this task?</p>
