Bypass DNS lookup and submit URL to proxy

我只是一个虾纸丫 提交于 2020-01-05 10:17:23

问题


I have Java application that uses Apache HttpComponents to make web request. I have configured the application to use Proxy Servers using the JVM Property

java -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=3132

Currently my java application client makes DNS lookup in which it will fail. I want the Proxy to do the DNS resolution just like how web browsers do in automatic Proxy configuration mode (with .pac files).


回答1:


Try looking here: http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientExecuteProxy.java

It seems as though you need to specify a proxy using setProxy() and not global properties.




回答2:


Just for the record this how one can make HttpClient pick up system proxy settings

CloseableHttpClient client = HttpClients.custom()
    .setRoutePlanner(
         new SystemDefaultRoutePlanner(ProxySelector.getDefault()))
    .build();

or this if you want HttpClient fully configured based on system prperties

CloseableHttpClient client = HttpClients.createSystem();


来源:https://stackoverflow.com/questions/20935617/bypass-dns-lookup-and-submit-url-to-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!