Java 无法通过代理进行隧道传输。“代理申报表”;HTTP/1.1 407需要代理授权”;

Java 无法通过代理进行隧道传输。“代理申报表”;HTTP/1.1 407需要代理授权”;,java,https,node-http-proxy,Java,Https,Node Http Proxy,我试图点击谷歌api的https url。 使用下面的代码,但会出现一些错误。 但是我可以点击一个GoogleAPIHTTPURL,它工作得很好,没有任何错误 DataInputStream di = null; FileOutputStream fo = null; byte[] b = new byte[1]; // PROXY System.setProperty("https.proxyHost", "my proxy"); System.setProperty("https.pr

我试图点击谷歌api的https url。 使用下面的代码,但会出现一些错误。 但是我可以点击一个GoogleAPIHTTPURL,它工作得很好,没有任何错误

DataInputStream di = null;

FileOutputStream fo = null;

byte[] b = new byte[1];

// PROXY
System.setProperty("https.proxyHost", "my proxy");
System.setProperty("https.proxyPort", "8080");


Authenticator.setDefault(new PasswordAuthenticator());


URL u = new URL("https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&sensor=true&key=keyforuse");

HttpURLConnection con = (HttpURLConnection) u.openConnection();

sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedUserPwd = encoder.encode("domain\\user:password"
        .getBytes());
con.setRequestProperty("Proxy-Authorization", "Basic "
        + encodedUserPwd);

di = new DataInputStream(con.getInputStream());
// result = parseJSON(di);
while (-1 != di.read(b, 0, 1)) {
    System.out.print(new String(b));
}
但是下面的错误

java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authorization Required"
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:1648)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:164)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1172)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
    at kf.store.locator.googlemaps.test.main(test.java:58)

任何帮助???

您可能不需要用户名前面的域。我有一个非常类似的问题,当我删除用户名前面的域时,我修复了它。由于代理服务器位于域上,我认为这意味着您的服务器位于同一域下

用户名前面可能不需要域。我有一个非常类似的问题,当我删除用户名前面的域时,我修复了它。由于代理服务器位于域上,我认为这意味着您的服务器位于同一域下

我通过使用用户名和密码向代理服务器进行身份验证来修复它。如果您在公司的网络上,它也可以是您的sso信誉。 与此类似的情况如下:

-Dhttp.proxyUser=myusername 
-Dhttp.proxyPassword=mypassword
-Dhttp.proxyHost=myproxyserver.com
-Dhttp.proxyPort=9000

我通过使用我的用户名和密码对代理服务器进行身份验证来修复它。如果您在公司的网络上,它也可以是您的sso信誉。 与此类似的情况如下:

-Dhttp.proxyUser=myusername 
-Dhttp.proxyPassword=mypassword
-Dhttp.proxyHost=myproxyserver.com
-Dhttp.proxyPort=9000

我已删除该域并使用sun.misc.BASE64Encoder=new sun.misc.BASE64Encoder()下面的代码;字符串encodedUserPwd=encoder.encode(“386654:Jun1@2013“.getBytes());con.setRequestProperty(“代理授权”、“基本”+encodedUserPwd);仍在获取错误,无法通过代理进行隧道传输。代理返回“HTTP/1.1 400错误请求”如果需要任何帮助而不是添加编码的凭据,您是否尝试将它们添加到代理主机?System.setProperty(“https.proxyHost”,“用户:pass@proxyHost)不确定这是否有用,但值得一试。我以前也曾这样做过。除此之外,您的代码对我来说还不错。我已经删除了域,并使用下面的代码sun.misc.BASE64Encoder encoder=new sun.misc.BASE64Encoder();字符串encodedUserPwd=encoder.encode(“386654:Jun1@2013“.getBytes());con.setRequestProperty(“代理授权”、“基本”+encodedUserPwd);仍在获取错误,无法通过代理进行隧道传输。代理返回“HTTP/1.1 400错误请求”如果需要任何帮助而不是添加编码的凭据,您是否尝试将它们添加到代理主机?System.setProperty(“https.proxyHost”,“用户:pass@proxyHost)不确定这是否有用,但值得一试。我以前也曾这样做过。除此之外,您的代码在我看来还不错。这只适用于Apache HTTP客户端。JDK忽略http.proxyUser/password。这只适用于Apache http客户端。JDK忽略http.proxyUser/password。