Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BasicAuth {
- private String user;
- private String pass;
- public BasicAuth(String user, String pass) {
- if (TextUtils.isEmpty(user)) {
- throw new IllegalArgumentException("user cannot be null");
- }
- if (TextUtils.isEmpty(pass)) {
- throw new IllegalArgumentException("pass cannot be null");
- }
- this.user = user;
- this.pass = pass;
- }
- public String getHeaderValue() {
- byte[] bytes = String.format("%s:%s", user, pass).getBytes();
- String value = String.format("Basic %s", Base64.encodeToString(bytes, Base64.DEFAULT));
- return value.trim();
- }
- public String getHeaderName() {
- return "Authorization";
- }
- }
Add Comment
Please, Sign In to add comment