2010-10-04

在HttpClient使用Proxy

不管你是基於什麼樣的情形有這樣的需要,總之,程式碼片斷就如同下面:

HttpClient client= new HttpClient();
client.getHostConfiguration().setProxy("proxy.getway", port);
client.getParams().setAuthenticationPreemptive(true);
Credentials credential= new UsernamePasswordCredentials("username", "password");
client.getState().setProxyCredentials(AuthScope.ANY, defaultcreds);

沒有留言:

張貼留言