File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ ------
2
+ Async Http Client - Configuring Authentication: BASIC, DIGEST or NTLM
3
+ ------
4
+ Jeanfrancois Arcand
5
+ ------
6
+ 2012
7
+
8
+ Configuring Authentication: BASIC, DIGEST or NTLM
9
+
10
+ Configuring authentication with AsyncHttpClient is simple. You can configure it at the <<<Request>>> level using the
11
+ <<<RealmBuilder>>>:
12
+
13
+ +-----+
14
+ AsyncHttpClient client = new AsyncHttpClient();
15
+ Realm realm = new Realm.RealmBuilder()
16
+ .setPrincipal(user)
17
+ .setPassword(admin)
18
+ .setUsePreemptiveAuth(true)
19
+ .setScheme(AuthScheme.BASIC)
20
+ .build();
21
+ client.prepareGet("http://...").setRealm(realm).execute();
22
+ +-----+
23
+
24
+ You can also set the realm at the AsyncHttpClientConfig level:
25
+
26
+ +-----+
27
+ Builder builder = new AsyncHttpClientConfig.Builder();
28
+ Realm realm = new Realm.RealmBuilder()
29
+ .setPrincipal(user)
30
+ .setPassword(admin)
31
+ .setUsePreemptiveAuth(true)
32
+ .setScheme(AuthScheme.BASIC)
33
+ .build();
34
+ builder.setRealm(realm).build();
35
+ AsyncHttpClient client = new AsyncHttpClient(builder.build());
36
+ +-----+
37
+
38
+ The authentication type supported are <<<BASIC>>>, <<<DIGEST>>> and <<<NTLM>>>. You can also customize your own
39
+ authentication mechanism by using the Response Filter.
You can’t perform that action at this time.
0 commit comments