Skip to content

Instantly share code, notes, and snippets.

@ShinjiKobayashi
Last active April 28, 2016 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShinjiKobayashi/7776e72a8306a8ab6254548212374813 to your computer and use it in GitHub Desktop.
Save ShinjiKobayashi/7776e72a8306a8ab6254548212374813 to your computer and use it in GitHub Desktop.
DigestAuthSample
new Runnable() {
@Override
public void run() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
final Map<String, CachingAuthenticator> authCache = new ConcurrentHashMap<>();
final DigestAuthenticator authenticator = new DigestAuthenticator(new Credentials("hoge", "fuga"));
OkHttpClient client = builder.authenticator(authenticator)
.addInterceptor(new AuthenticationCacheInterceptor(authCache))
.build();
Retrofit retrofit = new Retrofit.Builder()
.client(client)
.baseUrl("http://x68000.q-e-d.net/~68user/net/sample/http-auth-digest/secret.html")
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
final ApiService service = retrofit.create(ApiService.class);
service.login().enqueue(new Callback<MyResponse>() {
@Override
public void onResponse(Call<MyResponse> call,
retrofit2.Response<MyResponse> response) {
Log.i("koba", "hogehoge");
}
@Override
public void onFailure(Call<MyResponse> call, Throwable t) {
Log.i("koba", "fugafuga");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment