急求解通过代理服务器访问internet资源遇到的问题!

nhisense 2004-05-08 01:34:01
有些公司的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();
}
}

...全文
48 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧