gpt4 book ai didi

java - RESTEasy 客户端框架身份验证凭据

转载 作者:搜寻专家 更新时间:2023-10-30 21:00:13 26 4
gpt4 key购买 nike

RESTEasy(一个 JAX-RS 实现)有一个很好的客户端框架,例如:

ServiceApi client = ProxyFactory.create(ServiceApi.class, baseUri);

您如何向此客户端提供 HTTP 身份验证凭据?

最佳答案

jnorris 的回答使用了一些已弃用的类。这是一种使用未弃用类的更新方法。

    import org.apache.http.HttpStatus;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.DefaultHttpClient;
...
DefaultHttpClient httpClient = new DefaultHttpClient();

Credentials credentials = new UsernamePasswordCredentials(userName,
password);
httpClient.getCredentialsProvider().setCredentials(
org.apache.http.auth.AuthScope.ANY, credentials);

ClientExecutor clientExecutor = new ApacheHttpClient4Executor(
httpClient);
proxy = ProxyFactory
.create(UserAccessProxy.class, host, clientExecutor);

关于java - RESTEasy 客户端框架身份验证凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1885844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com