1

Android クライアントから http ダイジェスト認証を行おうとしています。これは、接続してダイジェストを正常に実行するカール ラインです。

curl -i --digest --user 'c@c.com:500a436e-2d5d-4a2e-be82-19651f7ea904' -v https://localhost:8080/v1/resources/debug

これは、401 を返す私の Android クライアントでの 1 つの試みです。

AndroidHttpClient httpClient = AndroidHttpClient.newInstance("user agent");

String url = "http://localhost:8080/v1/resources/debug";
URL urlObj = new URL(url);
HttpHost host = new HttpHost(urlObj.getHost(), urlObj.getPort(), urlObj.getProtocol());
AuthScope scope = new AuthScope(urlObj.getHost(), urlObj.getPort());
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("c@c.com", "500a436e-2d5d-4a2e-be82-19651f7ea904");

CredentialsProvider cp = new BasicCredentialsProvider();
cp.setCredentials(scope, creds);
HttpContext credContext = new BasicHttpContext();
credContext.setAttribute(ClientContext.CREDS_PROVIDER, cp);

HttpGet job = new HttpGet(url);
HttpResponse response = httpClient.execute(host,job,credContext);
StatusLine status = response.getStatusLine();
System.out.println("#### " + status.toString());
httpClient.close();

これはクライアントでの 2 回目の試行で、これも 401 を返します。

DefaultHttpClient httpclient = new DefaultHttpClient();
DefaultHttpClient httpclient2 = new DefaultHttpClient();
HttpGet httpget = new HttpGet("https://localhost:8080/v1/resources/debug");

HttpResponse response = httpclient.execute(httpget);
System.out.println(response.getStatusLine());

if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
    Header authHeader = response.getFirstHeader(AUTH.WWW_AUTH);
    System.out.println("authHeader = " + authHeader);
    DigestScheme digestScheme = new DigestScheme(); 
    digestScheme.processChallenge(authHeader);   
    UsernamePasswordCredentials creds = new UsernamePasswordCredentials("c@c.com", "500a436e-2d5d-4a2e-be82-19651f7ea904
    httpget.addHeader(digestScheme.authenticate(creds, httpget));
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String responseBody = httpclient2.execute(httpget, responseHandler);
    System.out.println("responseBody : " + responseBody);
}

認証を機能させるために私が欠けているものを見ることができますか? curl ラインがうまく機能するため、サーバーの問題ではないことはわかっています。

4

0 に答える 0