【发布时间】:2014-05-06 16:01:47
【问题描述】:
我正在使用 apache httpclient 4.3.3 开发一个 rest 客户端,它支持 HTTP Basic 和 Digest 身份验证。 我需要一个带有摘要身份验证的 REST Web 服务示例来测试我的客户端。任何人都可以帮助我,即使是在线 REST Web 服务也非常感谢。
这是摘要认证的客户端代码:
final HttpHost targetHost = new HttpHost("localhost", 8080, "http");
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(user, password));
// Create AuthCache instance
final AuthCache authCache = new BasicAuthCache();
// Generate DIGEST scheme object and add it to the local auth cache
DigestScheme digestAuth = new DigestScheme();
// Suppose we already know the realm name
digestAuth.overrideParamter("realm", "some-realm");
// Suppose we already know the expected nonce value
digestAuth.overrideParamter("nonce", "some-nonce");
authCache.put(targetHost, digestAuth);
// Add AuthCache to the execution context
HttpClientContext context = HttpClientContext.create();
context.setAuthCache(authCache);
之后,我可以打电话:
RestClient genericRestClient = new GenericRestClient.Builder(METHOD_URL)
.setUser(DEFAULT_USER).setPassword(DEFAULT_PASS)
.setAuthType(AuthenticationType.DIGEST_AUTH)
.setHttpVersion(HTTPVersion.HTTP_1_1).build();
genericRestClient.doGet();
我需要使用带有摘要身份验证的 REST Web 服务来测试我的客户端。
我已经开始使用这个网络服务:
@GET
@Path("/get")
@Produces("application/json")
public Product getProduct(@Context HttpHeaders headers) {
.....
Product product = new Product();
product.setName("Product 1");
product.setQty(50);
return product;
感谢您提供的任何帮助
【问题讨论】:
-
您能否提供更多详细信息。
-
如..有什么问题?没有问题。
-
我需要一个带有摘要身份验证的 REST Web 服务示例来测试我的客户端。甚至欢迎在线网络服务。
标签: java rest authentication digest