0
새로운 httocomponent 클라이언트 모듈Httpcomponents 클라이언트 프록시 문제
을 사용하여 프록시를 통해 인터넷에 연결하려고 할 때 내가 직접 프록시 객체를 사용하는 경우 내가하고 HttpURLConnection의 모든 것이 잘 진행에 문제가 :
URL u = new URL("http://www.google.com");
Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("somehost", 8080));
HttpURLConnection con = (HttpURLConnection) u.openConnection(proxy);
con.setRequestMethod("GET");
System.out.println(con.getResponseCode());
는 이제 새로운 API와 동일한 작업을 수행하려고 :
HttpHost proxy = new HttpHost("somehost", 8080, "http");
httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpHost targetHost = new HttpHost("http://www.google.com");
HttpGet httpGet = new HttpGet("/");
try {
HttpResponse httpResponse = httpClient.execute(targetHost, httpGet);
System.out.println(httpResponse.toString());
} catch (Exception e) {
e.printStackTrace();
}
하지만 난이 얻을 :
를HTTP/1.1 407 Proxy Authentication Required (Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. ) [Via: 1.1 xxx, Proxy-Authenticate: Negotiate, Proxy-Authenticate: Kerberos, Proxy-Authenticate: NTLM, Connection: Keep-Alive, Proxy-Connection: Keep-Alive, Pragma: no-cache, Cache-Control: no-cache, Content-Type: text/html, Content-Length: 7079 ]
나는 또한 내가 nned 프록시하지만 결과를 반환 MyProxySelector
ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
httpClient.getConnectionManager().getSchemeRegistry(),new MyProxySelector());
httpClient.setRoutePlanner(routePlanner);
을 시도했다.
왜 새로운 API를 사용하면 코드 내부에 프록시 인증이 필요합니까?