HTTP错误407需要代理身份验证 [英] HTTP Error 407 Proxy authentication required

查看:2999
本文介绍了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());
    }
});

这篇关于HTTP错误407需要代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆