ダイジェスト認証のサンプルApache hc(httpクライアント)を実行しています。私は提供されているサンプル使用して、何も変更しませんでした:Apache HTTPクライアントサンプルがダイジェスト認証に失敗する
public static void main(String[] args) throws Exception {
HttpHost target = new HttpHost("httpbin.org", 80, "http");
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(target.getHostName(), target.getPort()),
new UsernamePasswordCredentials("user", "passwd"));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
try {
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate DIGEST scheme object, initialize it and add it to the local
// auth cache
DigestScheme digestAuth = new DigestScheme();
// Suppose we already know the realm name
digestAuth.overrideParamter("realm", "[email protected]");
// Suppose we already know the expected nonce value
digestAuth.overrideParamter("nonce", "b2c603bb7c93cfa197945553a1044283");
authCache.put(target, digestAuth);
// Add AuthCache to the execution context
HttpClientContext localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);
HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd");
System.out.println("Executing request " + httpget.getRequestLine() + " to target " + target);
for (int i = 0; i < 3; i++) {
CloseableHttpResponse response = httpclient.execute(target, httpget, localContext);
try {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
} finally {
response.close();
}
}
} finally {
httpclient.close();
}
}
を私は取得しています:私はhttp://httpbin.org/digest-auth/auth/user/passwdに直接行く場合はHTTP/1.1 401不正
をユーザー/ passwdのために私を促した後、提供しますページ。したがって、ウェブサイトは正しく機能しています。
何が悪いと思いますか?私はライブラリの最新バージョンを持っています。ブラウザ用
フィドラー認証(成功):
ませプロキシ認証ヘッダーが存在しません。
認可ヘッダが存在する:ダイジェスト名= "ユーザ"、= "[email protected]"、ノンス= "8ada87344eb5a10bf810bcc211205c24" レルム、 URI = "/ダイジェスト認証/認証/ユーザー/ passwdの"、 レスポンス= "ad22423e5591d14c90c6fe3cd762e64c"、 不透明= "361645844d957289c4c8f3479f76269f"、QOP = AUTH、NC = 00000001、 cnonce = "260d8ddfe64bf32e"
私のコードのためのフィドラー認証(失敗):
プロキシなし-Authorizatiオンヘッダーが存在します。
認証ヘッダーが存在する:ダイジェストユーザ名= "ユーザー"、= "[email protected]"、ナンス= "76af6c9c0a1f57ee5f0fcade2a5f758c" 分野、 URI = "http://httpbin.org/digest-auth/auth /ユーザ/ passwdの」、 応答= "745686e3f38ab40ce5907d41f91823e6"、QOP = AUTH、NC = 00000001、 cnonce = "634b618d5c8ac9af"、アルゴリズム= MD5、 不透明= "fe84ce11c48a7b258490600800e5e6df"
どのようにして領域をプログラム的に決定できますか?このコードは、多くのサーバーに接続している多くのコンピュータで実行されるライブラリ用です。だから私はそれをハードコーディングすることはできません。 –