我在我的一个程序中得到了提到的错误代码。我四处寻找关于Stackoverflow的解决方案,并试图遵循伊拉娜·普拉托诺夫和PPr报告的问题的建议。不幸的是,这些错误并没有解决。
作为下一步,我只是尝试运行伊拉娜·普拉托诺夫中的代码以及解决方案(在那里接受)。我的代码:包例子;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.URL;
public class MyProxyPass {
public MyProxyPass( String proxyHost, int proxyPort, final String userid, final String password, String url ) {
try {
/* Create a HttpURLConnection Object and set the properties */
URL u = new URL( url );
Proxy proxy = new Proxy( Proxy.Type.HTTP, new InetSocketAddress( proxyHost, proxyPort ) );
HttpURLConnection uc = (HttpURLConnection) u.openConnection( proxy );
Authenticator.setDefault( new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType().equals( RequestorType.PROXY )) {
return new PasswordAuthentication( userid, password.toCharArray() );
}
return super.getPasswordAuthentication();
}
} );
uc.connect();
/* Print the content of the url to the console. */
showContent( uc );
}
catch (IOException e) {
e.printStackTrace();
}
}
private void showContent( HttpURLConnection uc ) throws IOException {
InputStream i = uc.getInputStream();
char c;
InputStreamReader isr = new InputStreamReader( i );
BufferedReader br = new BufferedReader( isr );
String line;
while ((line = br.readLine()) != null) {
System.out.println( line );
}
}
public static void main( String[] args ) {
String proxyhost = "xxx.xxx.xx.xx";
int proxyport = xxxx;
final String proxylogin = "JOKER";
final String proxypass = "passxxx";
String url = "http://www.google.de";
String surl = "https://www.google.de";
System.setProperty("javax.net.ssl.trustStore", "C:\\Users\\JOKER\\Documents\\eclipse-jee-photon-R-win32\\eclipse");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
//new MyProxyPass( proxyhost, proxyport, proxylogin, proxypass, url ); // uncomment this line to see that the https request works!
//System.out.println( url + " ...ok" ); // uncomment this line to see that the https request works!
new MyProxyPass( proxyhost, proxyport, proxylogin, proxypass, surl );
System.out.println( surl + " ...ok" );
}
}但是,我仍然得到了与其他人报告的相同的错误:
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
https://www.google.de ...ok
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
at examples.MyProxyPass.<init>(MyProxyPass.java:32)
at examples.MyProxyPass.main(MyProxyPass.java:63)什么对别人有用,对我没有用:
我正在使用:
如果我要附上其他日志,请告诉我。
发布于 2018-10-04 15:57:17
公司代理是罪魁祸首!一旦我解决了这些问题,我上面发布的代码就运行顺利了。
发布于 2018-11-05 13:31:50
我遇到了另一种情况,我得到了同样的错误(有正确的代理细节)。
Could not retrive data: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"这一次的错误是由于Java版本的1.8.0_111。自这次Java更新以来,HTTPS隧道的基本身份验证一直是禁用的。这是通过将协议添加到disabledScheme列表(即lib/net.properties文件中的jdk.http.auth.tunneling.disabledSchemes=Basic )来实现的。
若要解决此错误,请通过将变量jdk.http.auth.tunneling.disabledSchemes设置为emtpy字符串为:‘-Djdk.http.auth.隧道eling.disabledSchemes=’,从而启用基本身份验证。
发布于 2022-02-19 01:18:54
我刚刚完成了同样的问题。
我的应用程序创建了一个HTTP传输实例,然后使用它向服务器发出请求。有一个选项可以将此传输配置为使用代理服务器。因此,在传输的配置方法中有一个代码:
System.setProperty("jdk.http.auth.tunneling.disabledSchemes","");
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxyUserName, proxyUserPassword.toCharArray());
}
});看起来不错,但是通过代理服务器的所有请求都失败了,只有这个例外:
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
然后我注意到,我的应用程序在创建传输(并执行上面的行)之前向服务器发出了一个请求,以获取一些数据。
现在查看堆栈跟踪处的这一行:
at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124)如果查看这个类的源代码,就会发现static块,其中jdk.http.auth.tunneling.disabledSchemes的值被缓存到一个静态字段中。然后sun.net.www.protocol.http.HttpURLConnection使用这个缓存的值。
结论:在类加载程序加载sun.net.www.protocol.http.HttpURLConnection之前,必须严格地在代码中设置jdk.http.auth.tunneling.disabledSchemes (通过发出请求或其他方式)。或者在程序参数或jre/lib/net.properties文件中设置它。否则,更改jdk.http.auth.tunneling.disabledSchemes的值不会产生任何影响。
https://stackoverflow.com/questions/52191507
复制相似问题