Created
February 12, 2019 14:34
-
-
Save raghunandankavi2010/04a42d6ceffe2f98c18d879fdbc3deac to your computer and use it in GitHub Desktop.
Okhttp authenticator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final OkHttpClient client = new OkHttpClient.Builder() | |
. authenticator(new Authenticator() { | |
@Override public Request authenticate(Route route, Response response) throws IOException { | |
if (response.request().header("Authorization") != null) { | |
return null; // Give up, we've already attempted to authenticate. | |
} | |
String credential = Credentials.basic("jesse", "password1"); | |
return response.request().newBuilder() | |
.header("Authorization", credential) | |
.build(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment