title: How to switch from HttpClient to HttpUrlConnection?
body: <p>I am creating an Android application and I send data from Android application to servlet through HttpClient. I use HttpPost method.</p>
  
  <p>I read in Android developer site that Apache HttpClient library has some bug in Android Froyo 2.2 and after all it's good practice to use HttpUrlConnection instead HttpPost. So I want to convert my HttpPost code to HttpUrlConnectio but don't know how.</p>
  
  <p>I am posting my Android code as well as servlet code here</p>
  
  <p>Android code</p>
  
  <pre><code>private String postData(String valueIWantToSend[]) 
      {
          // Create a new HttpClient and Post Header
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost(url);
          try 
          {
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
              nameValuePairs.add(new BasicNameValuePair("param1",valueIWantToSend[0]));
              nameValuePairs.add(new BasicNameValuePair("param2", valueIWantToSend[1]));
              nameValuePairs.add(new BasicNameValuePair("param3", valueIWantToSend[2]));
              nameValuePairs.add(new BasicNameValuePair("param4", valueIWantToSend[3]));
              nameValuePairs.add(new BasicNameValuePair("param5", valueIWantToSend[4]));
              nameValuePairs.add(new BasicNameValuePair("param6", valueIWantToSend[5]));
              nameValuePairs.add(new BasicNameValuePair("param7", valueIWantToSend[6]));
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              /* execute */
              HttpResponse response = httpclient.execute(httppost);
              HttpEntity rp = response.getEntity();
  
              //origresponseText=readContent(response);
          }
          catch (ClientProtocolException e) 
          {
              // TODO Auto-generated catch block
          } 
          catch (IOException e) 
          {
              // TODO Auto-generated catch block
          }
          return null;
      }
  </code></pre>
  
  <p>and here is my servlet code</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      response.setContentType("text/html");
      ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
      Enumeration paramNames = request.getParameterNames();
      String params[] = new String[7];
      int i=0;
  
      while(paramNames.hasMoreElements())
      {
          String paramName = (String) paramNames.nextElement();
          System.out.println(paramName);
  
  
          String[] paramValues = request.getParameterValues(paramName);
          params[i] = paramValues[0];
  
          System.out.println(params[i]);
  
          i++;
      }
  
  }
  </code></pre>