gpt4 book ai didi

java - 无法通过代理建立隧道。代理返回 "HTTP/1.1 407 Proxy Authorization Required"

转载 作者:行者123 更新时间:2023-11-29 09:30:32 27 4
gpt4 key购买 nike

我试图访问 google api 的 https url。使用下面的代码但它给出了一些错误。但我可以访问一个 google api http url,它运行良好,没有任何错误

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)

有什么帮助吗????

最佳答案

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

关于java - 无法通过代理建立隧道。代理返回 "HTTP/1.1 407 Proxy Authorization Required",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17452956/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com