I'm trying to add the Authorization to the request in my HttpURLConnection. I can add other properties, like Content-type or even custom properties, but when I try to add the Authorization property it just doesn't add it. This is my code:
try {
URL url = new URL("http://www.google.es");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestProperty("Authorization", "Bearer aqufbzkia.zsdkbdckbjae.AKbAbaudbf");
httpCon.setRequestProperty("my-property", "what-ever-value");
httpCon.setRequestProperty("Accept", "text/html");
System.out.println("------------------- Request Headers -----------------------");
Map<String, List<String>> requestHeaders = httpCon.getRequestProperties();
Set<String> requestHeader = requestHeaders.keySet();
for(String key : requestHeader)
System.out.println("Header: " + key + " : " + requestHeaders.get(key).toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The value of the Authorization is already encoded.
The output I get from the loop is this:
------------------- Request Headers -----------------------
Header: Accept : [text/html]
Header: my-property : [what-ever-value]
The Authorization is not being added to the request properties, kindly review and give feedback.