title: Setting header Authorization for https get request in Java
body: <p>I'm working on a client that consumes a rest API with header Authorization. I'm getting a hard time getting to work adding http header authorization. I'm using the code below:</p>
  
  <pre><code>package com.javap;
  
  import org.json.simple.JSONArray;
  import org.json.simple.JSONObject;
  import org.json.simple.parser.JSONParser;
  import org.json.simple.parser.ParseException;
  
  import javax.net.ssl.HttpsURLConnection;
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.security.KeyManagementException;
  import java.security.NoSuchAlgorithmException;
  import java.util.Arrays;
  import java.util.Collections;
  import java.util.Properties;
  import java.util.Scanner;
  
  public class Main {
      public static void main(String[] args) {
  
  
          try {
              sslUtil.turnOffSslChecking();
              Properties prop = new Properties();
              //InputStream input = null;
  
              InputStream input = Main.class.getResourceAsStream("./application.properties");
              prop.load(input);
  
              String address = prop.getProperty("address");
              String token = prop.getProperty("token");
  
              URL url = new URL(address + customerId);
              HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
             conn.setRequestProperty("Authorization",  "Bearer " +  token);
  
              conn.setRequestMethod("GET");
  
              conn.setRequestProperty("Accept", "application/json");
              conn.addRequestProperty("User-Agent", "Mozilla/4.0");
              conn.setRequestProperty("Content-Type", "text/plain");
              conn.setRequestProperty("charset", "UTF-8");
  
  
              conn.connect();
  
              if (conn.getResponseCode() != 200) {
                  hasSQ = "false";
                  throw new RuntimeException("Failed : HTTP error code : "
                          + conn.getResponseCode());
              }else {
                  Scanner sc = new Scanner(url.openStream());
                  while(sc.hasNext()){
                      inline += sc.nextLine();
                  }
                  sc.close();
                  conn.disconnect();
              }
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (ParseException e) {
              e.printStackTrace();
          } catch (NoSuchAlgorithmException e) {
              e.printStackTrace();
          } catch (KeyManagementException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>I get an error of 401. But using Postman, everything works fine, son it's defiintely not about the token. Any ideas on how this could be resolved? </p>
  
  <p>Thanks in advance</p>