使用NTLM身份验证时,最新的Apache HttpClient 4.1.1出现HTTP / 1.1 407错误
||
我正在尝试使用Apache HttpClient 4.1.1库(http://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html)从我公司的代理后面访问网站使用带有NTLM身份验证的ISA服务器,但是我不断收到HTTP 407代理身份验证所需的错误:
代码段
HttpHost proxy = new HttpHost(\"myProxyHost\", 80, \"http\");
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
NTCredentials creds = new NTCredentials(\"myWindowsUserName\", \"myWindowsPwd\", \"localhost\", \"myCompanyDomain\");
AuthScope authScope = new AuthScope(\"myProxyHost\", 80, \"\", \"NTLM\");
httpClient.getCredentialsProvider().setCredentials(authScope, creds);
HttpHost target = new HttpHost(\"www.google.com\", 80, \"http\");
HttpGet get = new HttpGet(\"/\");
System.out.println(\"executing request to \" + target + \" via \" + proxy);
HttpResponse rsp = httpClient.execute(target, get);
System.out.println(\"----------------------------------------\");
System.out.println(rsp.getStatusLine());
Header[] headers = rsp.getAllHeaders();
for (int i = 0; i<headers.length; i++) {
System.out.println(headers[i]);
}
System.out.println(\"----------------------------------------\");
O / P
通过http:// myProxyHost:80执行对http://www.google.com:80的请求
----------------------------------------
需要HTTP / 1.1 407代理身份验证(ISA服务器需要授权才能完成请求。拒绝访问Web代理筛选器。)
通过:1.1 myCompanyServer
代理授权:协商
代理验证:Kerberos
代理验证:NTLM
连接:保持活动
代理连接:保持活动
语法:无缓存
缓存控制:无缓存
内容类型:text / html
内容长度:4120
----------------------------------------
我在这里想念什么?
更新:
在同一环境中,使用JDK URL和URLConnection类的代码有效!
工作代码段
System.setProperty(\"http.proxyHost\", \"myProxyHost\");
System.setProperty(\"http.proxyPort\", \"80\");
URL url = new URL(\"http://www.google.com\");
URLConnection con = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
O / P
Google window.google = {kEI:\“ _ N3cTaLFMY6cvgOH9MypDw \”,...
没有找到相关结果
已邀请:
2 个回复
土投
脖呐