您的位置:首页 > 编程语言 > Java开发

Java: 使用proxy连接URL

2008-05-19 22:43 387 查看
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());
}

}
.............................................
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐