Skip to content

Commit 2f341aa

Browse files
Added Proxy Authentication ; fixes android-async-http#328
1 parent f1ab377 commit 2f341aa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,23 @@ public void setProxy(String hostname, int port) {
310310
final HttpParams httpParams = this.httpClient.getParams();
311311
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
312312
}
313+
/**
314+
* Sets the Proxy by it's hostname,port,username and password
315+
*
316+
* @param hostname the hostname (IP or DNS name)
317+
* @param port the port number. -1 indicates the scheme default port.
318+
* @param username the username
319+
* @param password the password
320+
*/
321+
public void setProxy(String hostname,int port,String username,String password){
322+
httpClient.getCredentialsProvider().setCredentials(
323+
new AuthScope(hostname, port),
324+
new UsernamePasswordCredentials(username, password));
325+
final HttpHost proxy = new HttpHost(hostname, port);
326+
final HttpParams httpParams = this.httpClient.getParams();
327+
httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
328+
}
329+
313330

314331
/**
315332
* Sets the SSLSocketFactory to user when making requests. By default,

0 commit comments

Comments
 (0)