Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 多身份验证方法ApacheHTTP客户端4.3+;_Android_Apache Httpclient 4.x_Apache Commons Httpclient - Fatal编程技术网

Android 多身份验证方法ApacheHTTP客户端4.3+;

Android 多身份验证方法ApacheHTTP客户端4.3+;,android,apache-httpclient-4.x,apache-commons-httpclient,Android,Apache Httpclient 4.x,Apache Commons Httpclient,我有几个不同身份验证类型的服务器。基本的,NTLM。我需要自动选择它的机制。我认为这是在尝试每种凭证类型,并选择成功的凭证类型。我在http客户机4.3中找到了一些方法,名为impl.client.HttpClientBuilder#setDefaultAuthSchemeRegistry,但是 我不知道如何使用它 第二个问题,如何控制auth方法的优先级。因为我想确定应该使用哪个url方法,然后想从上次请求的成功方法开始 PS到目前为止,我对每种类型的身份验证都有可行的实现。可以使用Reque

我有几个不同身份验证类型的服务器。基本的,NTLM。我需要自动选择它的机制。我认为这是在尝试每种凭证类型,并选择成功的凭证类型。我在http客户机4.3中找到了一些方法,名为impl.client.HttpClientBuilder#setDefaultAuthSchemeRegistry,但是

  • 我不知道如何使用它
  • 第二个问题,如何控制auth方法的优先级。因为我想确定应该使用哪个url方法,然后想从上次请求的成功方法开始

  • PS到目前为止,我对每种类型的身份验证都有可行的实现。

    可以使用
    RequestConfig

    RequestConfig requestConfig =  RequestConfig.custom()
            .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
            .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
            .build();
    
    本地执行上下文包含与请求执行相关的所有详细信息,包括目标主机和代理主机的身份验证状态

    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {
        HttpClientContext localContext = HttpClientContext.create();
        HttpGet httpget = new HttpGet("http://localhost/");
        CloseableHttpResponse response = httpclient.execute(httpget, localContext);
        try {
            System.out.println(response.getStatusLine());
            EntityUtils.consume(response.getEntity());
            AuthState targetAuthState = localContext.getTargetAuthState();
            if (targetAuthState.getAuthScheme() != null) {
                System.out.println("Target auth scheme: " +
                        targetAuthState.getAuthScheme().getSchemeName());
            }
            AuthState proxyAuthState = localContext.getProxyAuthState();
            if (proxyAuthState.getAuthScheme() != null) {
                System.out.println("Proxy auth scheme: " +
                        proxyAuthState.getAuthScheme().getSchemeName());
            }
    
        } finally {
            response.close();
        }
    } finally {
        httpclient.close();
    }
    

    人们通常不需要这样做。如果请求共享相同的执行上下文,HttpClient将自动重新使用最后一个已知的成功身份验证方案