URLConnection的问题

jjkkk 2004-05-12 08:28:48
在java 网络编程的时间
可以用URLConnection访问一个站点
但如果这个站点是国外站点的话
要用到代理服务器

在java代码里面如何设置代理服务器或是指定使用ie中的服务器?
...全文
108 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuwangjiang 2004-08-12
  • 打赏
  • 举报
回复
各位 不好意思 我不知道在那里提问 有个关于URLCONNECTION的问题

urlconnection下载多框架网页

请问哪位专家 用urlconnection下载多框架网页 怎么实现
http请求头里有多框架设置么 jdk1.4支持么

jjkkk 2004-05-13
  • 打赏
  • 举报
回复
呵呵,谢谢啦
试过了,可以的
那有没有办法可以取得ie的默认设置呢?
pleonheart 2004-05-12
  • 打赏
  • 举报
回复
这也可以啊,太牛了!!
tomcatjava 2004-05-12
  • 打赏
  • 举报
回复
可以设置http和socks代理的。如下:
System.getProperties().setProperty( "socksProxyHost",socksProxyHost);
System.getProperties().setProperty( "socksProxyPort",socksProxyPort);
System.getProperties().setProperty( "http.proxyHost",httpProxyHost);
System.getProperties().setProperty( "http.proxyPort",httpProxyPort);

然后设置用户名和密码:
public class MyAuthenticator extends Authenticator
{
private String username,password;

public MyAuthenticator(String username,String password)
{
this.username=username;
this.password=password;
}

protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username,password.toCharArray());
}
}//end MyAuthenticator

验证用户名和密码:
Authenticator.setDefault( new MyAuthenticator( username,password ) );

62,623

社区成员

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

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