Chinaunix首页 | 论坛 | 博客
  • 博客访问: 247958
  • 博文数量: 58
  • 博客积分: 2017
  • 博客等级: 大尉
  • 技术积分: 680
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-07 00:15
文章分类

全部博文(58)

文章存档

2011年(1)

2010年(7)

2009年(32)

2008年(18)

我的朋友

分类:

2010-03-13 01:09:56

How to connect to internet from Java program through a proxy? The answer is very simple Just add the following arguments to the virtual machine

    java -Dhttp.proxyHost=hostname -Dhttp.proxyPort=port -Dhttp.proxyUser=username  -Dhttp.proxyPassword=passowrd

or just put set these System properties using the code.

   System.getProperties().put("http.proxyHost", "hostname");
System.getProperties().put("http.proxyPort", "port");
System.getProperties().put("http.proxyUser", "username");
System.getProperties().put("http.proxyPassword", "password");

If your proxy doesn’t require an authentication, you just need to set proxyHost and proxyPort properties only.

But the fist method wouldn’t work if we are running our program from within Eclipse as we don’t have command line access. So to set the proxy properties in Eclipse just go to Run menu and click on Run. A dialog box would appear and in the first tab (Main tab) enter your main class and other information and in the Arguments tab under VM arguments just add the following line.

   -Dhttp.proxyHost=hostnmae -Dhttp.proxyPort=port
阅读(2597) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~