title: How do I get the json data from this HttpURLConnection implementation converted from cURL?
body: <p>Hi I have the following cURL</p>
  
  <pre><code>curl -X GET --header "api-key: sOmE-API-kEy" "https://api.data.gov.sg/v1/environment/uv-index?date=2016-06-01"
  </code></pre>
  
  <p>which I got from the website that provides data for smart nation their website returns proper json data using their forms but i would like to do this via code using an HttpURLConnection so far I am following the code references i found online but it's not working and I couldnt see what's wrong, i get the NetworkOnMainThreadException which I solved by implementing it as an AsyncTask but when I step in android studio debug its now returning with an FileNotFoundException. i also tried using the TrustedManager etc suggested below and it still has the same error. one thing i noticed is when I go to the website and click on the button and look at it in firebug the following is the one that is processessed ...</p>
  
  <pre><code>https://apiconsole-prod.apigee.net/smartdocs/v1/sendrequest?targeturl=https%3A%2F%2Fapi.data.gov.sg%2Fv1%2Fenvironment%2Fuv-index%3Fdate%3D2016-06-01&amp;_=1469245322558
  </code></pre>
  
  <p>but if i type directly from the browser the response has something like this...
  steps.oauth.v2.FailedToResolveAPIKey%22%7D%7D%7D", "responseStatusCode": "401"</p>
  
  <pre><code>    URL url = new URL("https://api.data.gov.sg/v1/environment/uv-index?date=2016-06-01");
      urlConn = (HttpURLConnection)url.openConnection();
      urlConn.setRequestMethod("GET");
      urlConn.setDoInput(true);
      urlConn.setDoOutput(true);
      urlConn.setRequestProperty("Content-Type", "application/json");
      urlConn.setRequestProperty("Accept", "application/json");
      urlConn.setRequestProperty("api-key", "sOmE-API-kEy");
  
      in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
      String line;
      StringBuilder buffer = new StringBuilder();
      while ((line = in.readLine()) != null) {
          buffer.append(line).append('\n');
      }
      // Chomp the last newline
      buffer.deleteCharAt(buffer.length() - 1);
  </code></pre>
  
  <p>**note apikey renamed for privacy</p>
  
  <p>so in short looking at the header data from firebug how to i complete my http code implementation</p>
  
  <pre><code>Accept  
  */*
  Accept-Encoding 
  gzip, deflate, br
  Accept-Language 
  en-US,en;q=0.5
  DNT 
  1
  Host    
  apiconsole-prod.apigee.net
  Origin  
  https://developers.data.gov.sg
  Referer 
  https://developers.data.gov.sg/datagovsg-apis/apis/get/environment/uv-index
  User-Agent  
  Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
  api-key: sOmE-API-kEy
  </code></pre>