如果是在公司內部環境使用HttpClient 4去連外部網站須走proxy才能通時,
將原來這行:
HttpClient httpclient = new DefaultHttpClient();
修改為(假設proxy是http://10.160.3.88:8080/):
HttpHost proxy = new HttpHost("10.160.3.88", 8080);
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
同時補上宣告:
<% @page import="org.apache.http.HttpHost" %>
<% @page import="org.apache.http.conn.params.ConnRoutePNames" %>
即可。