我正在使用HttpClient連接到需要BasicAUTH的主機。但代理不需要任何身份驗證。我已經將它設置如下:使用HttpProxy連接到具有預先認證的主機
private final HttpClient httpClient; // Spring injected
設置基本身份驗證:
private void setBasicAuth(final String username, final String password) {
httpClient.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(username, password));
httpClient.getParams().setAuthenticationPreemptive(true);
}
設置代理:
private void setProxy(final String proxyHost, final int proxyPort) {
hostConfiguration hostConfiguration = httpClient.getHostConfiguration();
hostConfiguration.setProxy(proxyHost, proxyPort);
}
但在運行代碼時,我得到以下警告。一切正常,但我也想擺脫警告(或至少明白爲什麼他們出現)
WARN o.a.c.httpclient.HttpMethodDirector - Required proxy credentials not available for BASIC <any realm>@proxy.XXXXXX.no:3128
WARN o.a.c.httpclient.HttpMethodDirector - Preemptive authentication requested but no default proxy credentials available
任何想法?
您是否考慮過我通過代理連接的主機確實需要我設置BasicAUTH進行身份驗證?這個例子看起來很好,但我的問題是,代理不需要身份驗證,但我代理的主機卻可以。這似乎是我錯誤地配置了一些東西,因爲代理假定我希望它使用BasicAUTH參數。 – 2011-04-16 01:34:45