title: How to use a Thread for neworking operations
body: <p>I have this function which does network operations.. (i.e post data into a webpage)..But I am getting android.os.NetworkOnMainThreadException..
  I understood that I have to use the networking operations on a Thread but I have no Idea how to do that...Could u guys please help me with my code..
  Thanks in advance.....
  Here is my method</p>
  
  <pre><code>     public static String excutePost(String targetURL, String urlParameters)
  {
    URL url;
    HttpURLConnection connection = null;  
    try {
  
  
      //Create connection
        url = new URL(targetURL);
        connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", 
             "application/x-www-form-urlencoded");
  
        connection.setRequestProperty("Content-Length", "" + 
                 Integer.toString(urlParameters.getBytes().length));
        connection.setRequestProperty("Content-Language", "en-US");  
  
        connection.setUseCaches (false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
  
        //Send request
        DataOutputStream wr = new DataOutputStream (
                    connection.getOutputStream ());
        wr.writeBytes (urlParameters);
        wr.flush ();
        wr.close ();
  
        //Get Response    
        InputStream is = connection.getInputStream();
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        String line;
        StringBuffer response = new StringBuffer(); 
        while((line = rd.readLine()) != null) {
          response.append(line);
          response.append('\r');
        }
        rd.close();
        return response.toString();
  
    } catch (Exception e) {
  
     String g=e.toString();
    Log.d("errererer", g);
      return null;
  
    } finally {
  
      if(connection != null) {
        connection.disconnect(); 
      }
    }
  } 
  </code></pre>