HTTP错误407需要代理身份验证
我正在尝试使用此代码访问该网址
I am trying to access the url by using this code
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();
这在我的窗口机器上工作正常,但这在linux机器上不起作用。我这样得到了错误
This is working fine in my window machine but this is not working in linux machine. i am getting eror like this
线程main中的异常java.io.IOException:服务器返回HTTP响应代码:407用于URL: http://www.google.com/
at sun.net .www.protocol.http.HttpURLConnection.getInputStream(未知来源)
at com.yahoo.Connection.main(Connection.java:31)
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 407 for URL: http://www.google.com/ at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at 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
但同样的错误,我试图在/ etc / profile 中设置导出http_proxy =但是没有用
But Same Error and i tried to set the export http_proxy= in /etc/profile but no use
不知道哪里出错了。
我有同样的问题。以下内容对我有用。
I had the same problem. The following worked for me.
Authenticator.setDefault(new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("username","password".toCharArray());
}
});