如何使用httpclient 4.3设置凭证字符集

时间:2015-08-28 13:39:59

标签: character-encoding apache-httpclient-4.x credentials

AuthPNames.CREDENTIAL_CHARSET已被弃用!?

我不知道如何解读:

  

(4.3)使用RequestConfig和构造函数参数   AuthSchemeProviders。

来自documentation

有谁能举个例子?

1 个答案:

答案 0 :(得分:1)

Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
        .register(AuthSchemes.BASIC, new BasicSchemeFactory(Consts.UTF_8))
        .register(AuthSchemes.DIGEST, new DigestSchemeFactory(Consts.UTF_8))
        .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
        .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory())
        .register(AuthSchemes.KERBEROS, new KerberosSchemeFactory())
        .build();

CloseableHttpClient client = HttpClients.custom()
        .setDefaultAuthSchemeRegistry(authSchemeRegistry)
        .build();