2016-08-09 4 views
0

HTTP 클라이언트를 Jsoup로 설정하여 프록시로 TOR을 사용하려고하지만 클라이언트를 Jsoup로 설정하는 방법을 찾을 수 없습니다. Jsoup을 알면 어떻게 할 수 있을지 궁금합니다. httpClient 구성이 필요하지 않습니까?httpClient를 jsoup로 구성하는 방법

+0

의 사용 가능한 복제 (http://stackoverflow.com [Jsoup (HTML 파서)에 프록시 지원을 추가하는 방법?]/questions/7482748/how-to-add-proxy-support-to-jsoup-html-parser) –

답변

1

Jsoup는 HttpClient를 사용하지 않습니다,하지만 당신은 사용하여 프록시를 설정할 수 있습니다

// Setup proxy 
Proxy proxy = new Proxy(Proxy.Type.HTTP, 
     InetSocketAddress.createUnresolved("127.0.0.1", 80)); 

// Setup the authenticator 
Authenticator authenticator = new Authenticator() { 

    public PasswordAuthentication getPasswordAuthentication() { 
     return (new PasswordAuthentication("user", 
       "password".toCharArray())); 
    } 
}; 
Authenticator.setDefault(authenticator); 

// Send a request using the proxy 
Document doc = Jsoup.connect("http://www.example.com/") 
     .proxy(proxy) 
     .get(); 
+0

응답 해 주셔서 감사합니다. 사용자 이름과 비밀번호를 사용하는 프록시에 대해 createUnresolved가 더 많은 매개 변수를 지원합니까? – user3900368

+0

@ user3900368 내 대답을 업데이트했습니다. –