我正在使用apache httpclient 4.3.3开发一个rest客户端,它支持HTTP Basic和Digest身份验证。 我需要一个带有摘要式身份验证的休息网络服务示例来测试我的客户。任何人都可以帮助我,甚至可以非常感谢在线休息网络服务。
这是摘要式身份验证的客户端代码:
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();
我需要使用摘要式身份验证来使用其他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;
感谢您提供的任何帮助