我在服务器端使用过Code igniter REST api。我已经为REST API设置了摘要式身份验证。我已经使用volley库在客户端(android)端发出http请求,并使用jsonObjectRequest来调用URL。因此,如果有人知道如何在摘要请求中放置摘要认证的标题,那么请帮助我。
答案 0 :(得分:0)
Description: "Hispanic"
Id: -2
答案 1 :(得分:0)
我从未检查过那些HttpDigestStack实现,但我可能会从这样的事情开始:
final String userName = "user";
final String password = "password";
// Instantiate the cache
Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap
DigestAuthenticator auth = new DigestAuthenticator() {
@Override
protected PasswordAuthentication requestPasswordAuthentication(String rHost, InetAddress rAddr, int rPort, String rProtocol, String realm, String scheme, URL rURL, Authenticator.RequestorType reqType) {
return new PasswordAuthentication(userName, password.toCharArray());
}
};
HurlStack.UrlRewriter urlRewriter = new HurlStack.UrlRewriter() {
String rewriteUrl(String url) {
return url;
}
};
HttpDigestStack digestStack = new HttpDigestStack(auth, urlRewriter);
// Set up the network to use HttpURLConnection as the HTTP client.
Network network = new BasicNetwork(digestStack);
// Instantiate the RequestQueue with the cache and network.
RequestQueue mRequestQueue = new RequestQueue(cache, network);