title: change from DefaultHttpClient to HttpURLConnection
body: <p>I am new in Android development and till now I am using DefaultHttpClient to make service call now I need to use HttpURlConnection as DefaultHttpClient is depricated. How can I achieve this???</p>
  
  <p>My code for DefaultHttpClient is</p>
  
  <pre><code> public String makeServiceCall(String url, int method,
                                    List&lt;NameValuePair&gt; params) {
          try {
              // http client
              DefaultHttpClient httpClient = new DefaultHttpClient();
              HttpEntity httpEntity = null;
  
  
              // Checking http request method type
              if (method == POST) {
                  HttpPost httpPost = new HttpPost(url);
                  // adding post params
                  if (params != null) {
                      httpPost.setEntity(new UrlEncodedFormEntity(params));
                  }
  
                  httpResponse = httpClient.execute(httpPost);
  
              } else if (method == GET) {
                  // appending params to url
                  if (params != null) {
                      String paramString = URLEncodedUtils
                              .format(params, "utf-8");
                      url += "?" + paramString;
                  }
                  HttpGet httpGet = new HttpGet(url);
  
                  httpResponse = httpClient.execute(httpGet);
  
              }
              httpEntity = httpResponse.getEntity();
              response = EntityUtils.toString(httpEntity);
              Constant.statusCode = httpResponse.getStatusLine().getStatusCode();
  
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          return response;
  
      }
  </code></pre>
  
  <p>I am calling this method in doInBackground of my AsyncTask as</p>
  
  <pre><code> ServiceHandler serviceHandler = new ServiceHandler();
                  String jsonResponse = serviceHandler.makeServiceCall(url, serviceHandler.POST, pairs);
  </code></pre>