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());
}
}
.............................................
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());
}
}
.............................................
相关文章推荐
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- JAVA HTTP连接(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- JAVA HTTP连接(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- java使用url和tns两种方式连接数据库执行存储过程
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端
- Java Http连接中使用代理Proxy及其验证
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端
- 关于Java.net.URL对象使用Proxy访问Internet资源
- Java和Android Http连接程序:使用java.net.URL 下载服务器图片到客户端
- 使用 Java 连接处于proxy(or 防火墙)之外的HTTP服务器
- Java Http连接中使用代理(Proxy)及其验证(Authentication)
- 面向基础系列之---Java网络编程---网络连接组件的使用(URLConnecti 3ff8 on)
- 关于Java.net.URL对象使用Proxy访问Internet资源
- java使用Jsoup连接网站超时的解决方法 链接的时候设定超时时间即可。 doc = Jsoup.connect(url).timeout(5000).get();