在 Eclipse 中为 http 请求使用代理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5150054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 15:53:09  来源:igfitidea点击:

Use proxy for http request in Eclipse

javaeclipseproxyhttp-proxy

提问by user496949

For debugging purposes, I need to configure Java to use a proxy for HTTP requests. I am wondering how to do it in my Eclipse environment when I press Ctrl+ F11? Any help will be appreciated.

出于调试目的,我需要将 Java 配置为对 HTTP 请求使用代理。我想知道当我按下Ctrl+时如何在我的 Eclipse 环境中做到这一点F11?任何帮助将不胜感激。

回答by CoolBeans

You need to pass these flags in your run configuration. Run -> Run configurations -> Select your project. Then in second tab: “Arguments”. Top box is for your program's arguments, and bottom box is for VM arguments. Add these two there as VM arguments.

您需要在运行配置中传递这些标志。运行 -> 运行配置 -> 选择您的项目。然后在第二个选项卡中:“参数”。顶部框用于您的程序参数,底部框用于 VM 参数。在那里添加这两个作为 VM 参数。

-Dhttp.proxyHost=proxyserver.com  
-Dhttp.proxyPort=80

You can also set them in your code.

您也可以在代码中设置它们。

System.setProperty("http.proxyHost", "proxyserver.com");
System.setProperty("http.proxyPort", "80");

You can read more about them in java docs here.

您可以在此处的Java 文档中阅读有关它们的更多信息。

回答by Souvick Mazumder

If its still not working add these also as VM variables in run config.

如果它仍然不起作用,请将这些也添加为运行配置中的 VM 变量。

-Dhttps.proxyHost=proxyserver.com
-Dhttps.proxyPort=80

-Dhttps.proxyHost=proxyserver.com
-Dhttps.proxyPort=80