[英]Fetching web pages with proxy in Java-based web services
我的網絡服務將使用代理獲取一些網頁:
System.setProperty("java.net.useSystemProxies", "true");
List<Proxy> proxies = ProxySelector.getDefault().select(new URI(url));
URLConnection connection = null;
Iterator<Proxy> iter = proxies.iterator();
do {
Proxy proxy = iter.next();
System.out.println(proxy);
try {
connection = new URL(url).openConnection(proxy);
} catch (IOException e) {
if (!iter.hasNext()) throw (e);
}
} while (connection == null);
但是,默認的ProxySelector始終返回直接連接(無代理)。 我已經檢查了IE代理設置,並將Java控制面板中的代理設置設置為系統瀏覽器設置。
由於Web服務是由Tomcat服務器調用的,因此也許必須在Tomcat服務器中完成一些配置?
請查看此鏈接。
http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.