【发布时间】:2019-02-10 23:24:54
【问题描述】:
我在我的一个程序中收到了主题提到的错误代码。我在 Stackoverflow 上四处寻找解决方案,并尝试遵循 Ilana Platonov 和 PPr 报告的问题的建议。不幸的是,这些并没有解决错误。
下一步,我只是尝试运行Ilana Platonov 中提供的代码以及解决方案(在那里接受)。我的代码: 包示例;
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)
什么对别人有用,对我没用:
关于将变量 jdk.http.auth.tunneling.disabledSchemes 和 jdk.http.auth.proxying.disabledSchemes 设置为空白的常见建议不起作用。我在 ..\Java\jdk1.8.0_112\jre\lib\net.properties 文件中将这些设置为空白。
使用Andreas Panagiotidis 提出的各种 JVM Args 也无济于事。
- 来自https://bugs.eclipse.org/bugs/show_bug.cgi?id=422665 我还尝试排除可能存在冲突的HTTP 库。 -Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4
我正在使用:
- Eclipse IDE 光子发布 (4.8.0),
- java 版本“1.8.0_112”(内部版本 1.8.0_112-b15)
- Windows 10
- 我支持公司代理,并且在这方面花了整整两天时间,但没有成功。 :(
如果我应该附上任何其他日志,请告诉我。
【问题讨论】:
标签: java proxy http-tunneling http-status-code-407