java HttpURLConnection隧道错误407

时间:2018-09-05 18:35:31

标签: java proxy http-tunneling http-status-code-407

我在我的一个程序中得到该主题提到的错误代码。我到处寻找关于Stackoverflow的解决方案,并尝试遵循Ilana PlatonovPPr报告的问题的建议。不幸的是,这些并不能解决错误。

下一步,我只是尝试运行Ilana Platonov中提供的代码以及解决方案(在那里接受)。我的代码:     包示例;

imagesc(imageStack(:,:,1)

但是,我仍然收到其他人报告的错误:

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" );
}
}

对别人有用而不对我有用的东西

  1. 关于将变量jdk.http.auth.tunneling.disabledSchemes和jdk.http.auth.proxying.disabledSchemes设置为空白的常见建议不起作用。我在.. \ Java \ jdk1.8.0_112 \ jre \ lib \ net.properties文件中将它们设置为空白。

  2. 使用Andreas Panagiotidis 提出的各种JVM Arg都没有帮助。

  3. 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 Photon发行版(4.8.0),
  • java版本“ 1.8.0_112”(内部版本1.8.0_112-b15)
  • Windows 10
  • 我在公司委托书的后面,花了整整两天的时间才取得成功。 :(

让我知道是否应该附加其他任何日志。

2 个答案:

答案 0 :(得分:1)

公司代理人是罪魁祸首!解决这些问题后,我上面发布的代码可以正常工作。

答案 1 :(得分:1)

我遇到另一种情况,我遇到相同的错误(具有正确的代理详细信息)。

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隧道的基本身份验证。这是通过在lib / net.properties文件中将协议添加到DisabledScheme列表即jdk.http.auth.tunneling.disabledSchemes = Basic来完成的。

要解决此错误,请通过将变量jdk.http.auth.tunneling.disabledSchemes设置为emtpy string来启用基本身份验证,如下所示: '-Djdk.http.auth.tunneling.disabledSchemes ='

Enable/Disable Basic Authentication for HTTPS

相关问题