我试图通过使用此代码访问该URL
System.setProperty("http.proxyHost", "111.88.15.108");
System.setProperty("http.proxyPort", "8002");
System.setProperty("http.proxyUser", "user");
System.setProperty("http.proxyPassword", "password");
URL oracle = new URL("http://www.google.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
in.close();
Run Code Online (Sandbox Code Playgroud)
这在我的窗口机器上工作正常,但这在linux机器上不起作用.我这样变得很恐怖
线程"main"中的异常java.io.IOException:服务器返回HTTP响应代码:407为URL:http://www.google.com/ at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)在com.yahoo.Connection.main(Connection.java:31)
即使代理设置是正确的,我也尝试过
java -Dhttp.proxyHost="111.88.15.108" -Dhttp.proxyPort="8002" -Dhttp.proxyUser="user" -Dhttp.proxyPassword="password" -jar yahoo_test3.jar
Run Code Online (Sandbox Code Playgroud)
但相同的错误,我试图在/ etc/profile中设置导出http_proxy =但没有用
知道哪里出错了.
小智 9
我有同样的问题.以下对我有用.
Authenticator.setDefault(new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("username","password".toCharArray());
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14787 次 |
| 最近记录: |