Last active
April 28, 2016 16:37
-
-
Save ShinjiKobayashi/7776e72a8306a8ab6254548212374813 to your computer and use it in GitHub Desktop.
DigestAuthSample
This file contains 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
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