我正在测试Apache HttpAsyncClient,特别是我想在需要身份验证的地方发出异步 HTTP POST 请求。我用这个例子作为参考。到目前为止,我发现了如何设置应用程序类型和正文,但不知道如何设置凭据。
我尝试添加身份验证凭据
HttpAsyncClientBuilder create = HttpAsyncClientBuilder.create();
create.setTargetAuthenticationStrategy(new TargetAuthenticationStrategy());
BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider();
Credentials defaultcreds = new UsernamePasswordCredentials("user", "password");
basicCredentialsProvider.setCredentials(new AuthScope("http://localhost", 7351), defaultcreds);
create.setDefaultCredentialsProvider(basicCredentialsProvider);
final CloseableHttpAsyncClient httpclient = create.build();
httpclient.start();
...
但我总是得到
Sep 11, 2013 4:21:35 PM org.apache.http.impl.auth.HttpAuthenticator handleAuthChallenge
WARNING: Malformed challenge: Authentication challenge is empty
我还没有找到解释如何为 CloseableHttpAsyncClient 设置身份验证数据的示例。任何人都可以帮助我吗?