Skip to content

Commit 0758d02

Browse files
committed
Added Proxy to interface, Fixes android-async-http#210
1 parent fe7848f commit 0758d02

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/src/com/loopj/android/http/AsyncHttpClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.http.Header;
2424
import org.apache.http.HeaderElement;
2525
import org.apache.http.HttpEntity;
26+
import org.apache.http.HttpHost;
2627
import org.apache.http.HttpRequest;
2728
import org.apache.http.HttpRequestInterceptor;
2829
import org.apache.http.HttpResponse;
@@ -42,6 +43,7 @@
4243
import org.apache.http.client.protocol.ClientContext;
4344
import org.apache.http.conn.params.ConnManagerParams;
4445
import org.apache.http.conn.params.ConnPerRouteBean;
46+
import org.apache.http.conn.params.ConnRoutePNames;
4547
import org.apache.http.conn.scheme.PlainSocketFactory;
4648
import org.apache.http.conn.scheme.Scheme;
4749
import org.apache.http.conn.scheme.SchemeRegistry;
@@ -254,6 +256,18 @@ public void setTimeout(int timeout) {
254256
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
255257
}
256258

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+
257271
/**
258272
* Sets the SSLSocketFactory to user when making requests. By default,
259273
* a new, default SSLSocketFactory is used.

0 commit comments

Comments
 (0)