首页 > 编程学习 > Java: 使用proxy连接URL

Java: 使用proxy连接URL

发布时间:2022/6/23 23:38:34
Java: 使用proxy连接URL

The Authenticator method isn't working for me, using JDK 1.3.1_06 and JSSE 1.0.3_01. I still get the 407 error. My code works just fine under 1.4.1, however.

Is there a way to make it work under 1.3.1. Are other people having these problems with it?

Here's my code:
// get proxy and port from command line
SecureClient.proxyhost = args[2]; //
SecureClient.proxyport = args[3]; //


// set the JSSE system properties
System.setProperty("https.proxyHost", SecureClient.proxyhost);
System.setProperty("https.proxyPort", SecureClient.proxyport);


System.out.println("using proxy: "+ SecureClient.proxyhost + " port " + SecureClient.proxyport);


// now create http authentication


// this didn't work
// System.setProperty("http.proxyUser", "myuser");
// System.setProperty("http.proxyPassword", "mypassword");


// this worked in 1.4.1
Authenticator.setDefault( new httpAuthenticateProxy() );
..........................................

and here's my authenticator class:

public class httpAuthenticateProxy extends Authenticator {

protected PasswordAuthentication getPasswordAuthentication() {
// username, password
// sets http authentication
return new PasswordAuthentication("myuser","mypassword".toCharArray());
}

}
.............................................

posted on 2008-05-19 22:43 浙林龙哥 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/huqingyu/archive/2008/05/19/1202874.html

Copyright © 2010-2022 ngui.cc 版权所有 |关于我们| 联系方式| 豫B2-20100000