Create a gist now

Instantly share code, notes, and snippets.

Embed
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