getRequestProperty("Authorization") always returns null
Posted
by Thilo
on Stack Overflow
See other posts from Stack Overflow
or by Thilo
Published on 2010-05-19T08:56:28Z
Indexed on
2010/05/19
9:00 UTC
Read the original article
Hit count: 268
I am trying to read the authorization header for an HTTP request (because I need to add something to it), but I always get null for the header value. Other headers work fine.
public void testAuth() throws MalformedURLException, IOException{
URLConnection request = new URL("http://google.com").openConnection();
request.setRequestProperty("Authorization", "MyHeader");
request.setRequestProperty("Stackoverflow", "anotherHeader");
// works fine
assertEquals("anotherHeader", request.getRequestProperty("Stackoverflow"));
// Auth header returns null
assertEquals("MyHeader", request.getRequestProperty("Authorization"));
}
Am I doing something wrong? Is this a "security" feature? Is there a way to make this work with URLConnection, or do I need to use another HTTP client library?
© Stack Overflow or respective owner