title: How to use the new URLConnection for Urlshortner in android
body: <p>i am trying to change  HTTPClient deprecated  code but i get i/o exception always and i dont know where i am wrong.
  <strong>my old deprecated  code snippt</strong></p>
  
  <pre><code>  public JSONObject getJSONFromUrl(String address, String longUrl) {
       // Making HTTP request
       try {
          // DefaultHttpClient
          DefaultHttpClient httpClient = new DefaultHttpClient();
          HttpPost httpPost = new HttpPost(address);
  
          httpPost.setEntity(new StringEntity("{\"longUrl\":\"" + longUrl + "\"}"));
          httpPost.setHeader("Content-Type", "application/json");
          HttpResponse httpResponse = httpClient.execute(httpPost);
  
          HttpEntity httpEntity = httpResponse.getEntity();
          is = httpEntity.getContent();
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>my new not working code snippt</strong></p>
  
  <pre><code> try {
      HttpURLConnection httpcon = (HttpURLConnection) ((new          URL(address).openConnection()));
      httpcon.setDoOutput(true);
      httpcon.setRequestProperty("Content-Type", "application/json");
      httpcon.setRequestMethod("POST");
      httpcon.connect();
  
   //   byte[] outputBytes = "{'value': 7.5}".getBytes("UTF-8");
     is = httpcon.getInputStream();
   /*   os.write(outputBytes);
  
      os.close();*/
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
      catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>