我想读HTTP请求的授权头(因为我需要添加一些东西给它),但我总是得到空头值。其他头文件工作正常。getRequestProperty(“授权”)总是返回空
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"));
}
我做错了什么?这是一个“安全”功能吗?有没有办法使URLConnection这项工作,还是我需要使用另一个HTTP客户端库?
这将解释它。此外,为什么相同的代码在Google App Engine上运行良好(他们使用自己的HttpUrlConnection实现)。 – Thilo 2010-05-21 07:18:52