How to set proxy host on HttpClient request in Java

前端 未结 4 1138
野趣味
野趣味 2021-01-12 13:13

I want to set proxy before sending HttpClient request on a URL. As I am able to connect it curl command setting up the proxy but with Java code I am not able to

4条回答
  •  天涯浪人
    2021-01-12 13:59

    System properties usually have to be set right upfront, which means either in the jvm startup with -Dhttp.proxyHost=some.host.com -Dhttp.proxyPort=8080, not forgetting the httpsProxyHost and ...Port)

    Or which should work, too, in a static {} block.

    I personally find the Jersey client implementation easier to work with, if you have the option to switch.

提交回复
热议问题