|
23 | 23 | import org.apache.http.Header;
|
24 | 24 | import org.apache.http.HeaderElement;
|
25 | 25 | import org.apache.http.HttpEntity;
|
| 26 | +import org.apache.http.HttpHost; |
26 | 27 | import org.apache.http.HttpRequest;
|
27 | 28 | import org.apache.http.HttpRequestInterceptor;
|
28 | 29 | import org.apache.http.HttpResponse;
|
|
42 | 43 | import org.apache.http.client.protocol.ClientContext;
|
43 | 44 | import org.apache.http.conn.params.ConnManagerParams;
|
44 | 45 | import org.apache.http.conn.params.ConnPerRouteBean;
|
| 46 | +import org.apache.http.conn.params.ConnRoutePNames; |
45 | 47 | import org.apache.http.conn.scheme.PlainSocketFactory;
|
46 | 48 | import org.apache.http.conn.scheme.Scheme;
|
47 | 49 | import org.apache.http.conn.scheme.SchemeRegistry;
|
@@ -254,6 +256,18 @@ public void setTimeout(int timeout) {
|
254 | 256 | HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
|
255 | 257 | }
|
256 | 258 |
|
| 259 | + /** |
| 260 | + * Sets the Proxy by it's hostname and port |
| 261 | + * |
| 262 | + * @param hostname the hostname (IP or DNS name) |
| 263 | + * @param port the port number. -1 indicates the scheme default port. |
| 264 | + */ |
| 265 | + public void setProxy(String hostname, int port){ |
| 266 | + final HttpHost proxy = new HttpHost(hostname, port); |
| 267 | + final HttpParams httpParams = this.httpClient.getParams(); |
| 268 | + httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); |
| 269 | + } |
| 270 | + |
257 | 271 | /**
|
258 | 272 | * Sets the SSLSocketFactory to user when making requests. By default,
|
259 | 273 | * a new, default SSLSocketFactory is used.
|
|
0 commit comments