Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support for BasicAuth using UsernamePasswordsCredentials #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 7, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/com/loopj/android/http/AsyncHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void process(HttpRequest request, HttpContext context) {
request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
}
for (String header : clientHeaderMap.keySet()) {
request.addHeader(header, clientHeaderMap.get(header));
request.addHeader(header, clientHeaderMap.get(header));
}
}
});
Expand Down Expand Up @@ -239,7 +239,31 @@ public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
* @param value the contents of the header
*/
public void addHeader(String header, String value) {
clientHeaderMap.put(header, value);
clientHeaderMap.put(header, value);
}

/**
* Sets basic authentication for the request. Uses AuthScope.ANY. This is the same as
* setBasicAuth('username','password',AuthScope.ANY)
* @param username
* @param password
*/
public void setBasicAuth(String user, String pass){
AuthScope scope = AuthScope.ANY;
setBasicAuth(user, pass, scope);
}

/**
* Sets basic authentication for the request. You should pass in your AuthScope for security. It should be like this
* setBasicAuth("username","password", new AuthScope("host",port,AuthScope.ANY_REALM))
* @param username
* @param password
* @param scope - an AuthScope object
*
*/
public void setBasicAuth( String user, String pass, AuthScope scope){
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user,pass);
this.httpClient.getCredentialsProvider().setCredentials(scope, credentials);
}

/**
Expand Down