代理服务器的问题?

newchina 2003-09-15 05:59:24
我想通过http协议访问web上的html文件
中件可能需要通过代理服务器,
谁能提供一个代码例子或者指点一下到哪里找资料,谢谢!
...全文
89 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
punpuny 2003-09-15
  • 打赏
  • 举报
回复
Properties prop = System.getProperties();

prop.put("http.proxyHost", proxyHost);
prop.put("http.proxyPort", proxyPort);
System.setProperties(prop);

其中的proxyHost和proxyPort是代理服务器的地址和端口。
chaojinn 2003-09-15
  • 打赏
  • 举报
回复
System.setProperty( "http.proxyHost", "ip" );
System.setProperty( "http.proxyPort", "port" );
fast_time 2003-09-15
  • 打赏
  • 举报
回复
try {
System.setProperty( "http.proxyHost", "192.168.1.5" );
System.setProperty( "http.proxyPort", "8085" );
java.net.URL url = new java.net.URL( "http://www.3721.com/install/install.htm" );
URLConnection conn = url.openConnection();
InputStream sslin = conn.getInputStream();
InputStreamReader inReader = new InputStreamReader( sslin );
BufferedReader in = new BufferedReader( inReader );

PrintStream out = new PrintStream( new FileOutputStream( "D:\\aa.txt" ) );
String line;
while ( null != ( line = in.readLine() ) ) {
out.println( line );
}
in.close();
} catch ( Exception e ) {
System.out.println( "error occured : " + e.getMessage() );
}

62,635

社区成员

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

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