急求解通过代理服务器访问internet资源遇到的问题!
有些公司的http代理服务器需要身份验证,包括域名、用户名、密码等信息。
我使用如下方式,但是总不能成功。希望各位大哥指点:
(http代理服务器不需要身份验证的时候可以通过) 代码如下:
public class Post {
public Post() {
}
public static void main(String[] args) throws Exception{
Post post1 = new Post();
Properties prop = System.getProperties();
prop.put( "http.proxySet", "true" );
prop.put( "http.proxyHost", "10.1.2.13" );
prop.put( "http.proxyPort", "80" );
// prop.put( "http.auth.ntlm.domain", "wonders_files" );
prop.put( "http.proxyType", "4");
String urlstring = "http://www.sina.com.cn/";
String parameters = "name=value1&age=value2";
URL url = new URL(urlstring);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("Proxy-Authorization","Basic mydomain\\username:password");
conn.setRequestMethod("GET");
conn.connect(); // throws IOException
InputStream input = conn.getInputStream();
File file = new File("D:/420/sina.html");
FileOutputStream fos = new FileOutputStream(file);
byte[] b = new byte[8192];
int count = 0;
while(true){
if((count=input.read(b))==-1) break;
fos.write(b,0,count);
}
fos.close();
}
}
我使用如下方式,但是总不能成功。希望各位大哥指点:
(http代理服务器不需要身份验证的时候可以通过) 代码如下:
public class Post {
public Post() {
}
public static void main(String[] args) throws Exception{
Post post1 = new Post();
Properties prop = System.getProperties();
prop.put( "http.proxySet", "true" );
prop.put( "http.proxyHost", "10.1.2.13" );
prop.put( "http.proxyPort", "80" );
// prop.put( "http.auth.ntlm.domain", "wonders_files" );
prop.put( "http.proxyType", "4");
String urlstring = "http://www.sina.com.cn/";
String parameters = "name=value1&age=value2";
URL url = new URL(urlstring);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestProperty("Proxy-Authorization","Basic mydomain\\username:password");
conn.setRequestMethod("GET");
conn.connect(); // throws IOException
InputStream input = conn.getInputStream();
File file = new File("D:/420/sina.html");
FileOutputStream fos = new FileOutputStream(file);
byte[] b = new byte[8192];
int count = 0;
while(true){
if((count=input.read(b))==-1) break;
fos.write(b,0,count);
}
fos.close();
}
}
...全文
相关推荐
如何利用NAT技术实现局域网用户访问Internet
利用NAT技术实现局域网用户接入互联网详细介绍 让你无需烦恼
JAVA 通过proxy代理方式访问internet资源
JAVA 通过proxy代理方式访问internet资源,
基于wininet下的HTTP访问之代理服务器 源代码
基于wininet技术集合c++写的源代码,可以实现用代理服务器来访问URL页面,不是vc++,所以页面显示只是HTML的源代码。zhaquanmin@163.com
Linux下用Squid实现局域网用户访问Internet的身份验证.pdf
Linux下用Squid实现局域网用户访问Internet的身份验证.pdf
代理服务器proxy
代理服务器(Proxy Server)是一种重要的安全功能,它的工作主要在开放系统互联(OSI)模型的对话层,从而起到防火墙的作用。代理服务器大多被用来连接INTERNET(国际互联网)和INTRANET(局域网)。


Web 开发
