我已經搜索了很多這個主題,但不明白爲什麼如果我嘗試在我的Java應用程序中使用Web服務,我會失敗,而不執行此代碼段以及:Java默認身份驗證與代理參數
final String authUser = "myUser";
final String authPassword ="******";
Authenticator.setDefault(
new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
authUser, authPassword.toCharArray());
}
}
);
...我不喜歡在這裏「雕刻」我的憑據,或者在屬性文件中。 我寧願使用「運行方式」 VM參數......所以,如果我評論上面的代碼並運行我的應用程序:
-Dhttps.proxyHost=proxy.test.it
-Dhttp.proxyPort=3128
-Dhttp.proxyUsername=myUser
-Dhttps.proxyPassword=****
-Danypoint.platform.proxy_username=myUser
-Danypoint.platform.proxy_password=****
-Danypoint.platform.proxy_host=proxy.test.it
-Danypoint.platform.proxy_port=3128
-Djava.net.useSystemProxies=true
-Dhttp.nonProxyHosts=...
或...
System.setProperty("http.proxyUser", authUser);
System.setProperty("http.proxyPassword", authPassword);
System.setProperty("http.nonProxyHosts","myHost");
System.setProperty("useSystemProxies","true");
它贏得沒有工作。我真的不明白。
感謝支持!
你總是可以做'字符串AUTHUSER = System.getProperty(「http.proxyUser」)'所以它的價值不是在硬編碼的代碼,但肯定CMD線 – ZhongYu
讀,但它不工作!請讀我的句子。如果和只有如果我把firt java腳本,電話將不會失敗... –