Apache HttpClient - NTLM:500 内部服务器错误

Apache HttpClient - NTLM : 500 Internal Server Error

我正在使用 Apache HttpClient 版本 4.5.3 从网络服务 (Microsoft-IIS/8.5) 获取一些信息。

因此需要 NTLM 身份验证。但是在此过程结束时我收到 500 Internal Server Error,尽管一切似乎都运行良好(发送 messagetype1、接收质询、发送 messagetype3)。

下面的代码,如果你能提供一些帮助来解决这个错误,谢谢。

String workstation = "someurl.com";
String domain ="DOMBIN";
String userName = "KSY5989";

String soapMessage ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"https://tempuri.org/\">"+
        "<soapenv:Header/>"+ 
        "<soapenv:Body>"+
        "<tem:GetPass>"+
            "<tem:PasswordWSRequest>"+
                "<tem:UserName>user658</tem:UserName>"+
                "<tem:Address>someurl.com</tem:Address>"+
                "<tem:ConnectionTimeout>60</tem:ConnectionTimeout>"+
            "</tem:PasswordWSRequest>"+
        "</tem:GetPass>"+
        "</soapenv:Body>"+
        "</soapenv:Envelope>";


SSLContext sslContext = SSLContexts
         .custom()
         //FIXME to contain real trust store
         .loadTrustMaterial(new TrustStrategy() {
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                // TODO Auto-generated method stub
                return true;
            }

         })
         .build();

Registry<AuthSchemeProvider> authSchemeRegistry2 = RegistryBuilder.<AuthSchemeProvider>create()
        .register(AuthSchemes.NTLM, new NTLMSchemeFactory())
        .build();

NTCredentials credentials = new NTCredentials(userName, password, workstation, domain);

CredentialsProvider credsProvider = new BasicCredentialsProvider();             
credsProvider.setCredentials(AuthScope.ANY, credentials);

try(CloseableHttpClient httpClient = HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry2).setSSLContext(sslContext).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()){

    HttpHost target = new HttpHost("someurl.net", 5489, "https");

    HttpClientContext context = HttpClientContext.create();
    context.setCredentialsProvider(credsProvider);

    HttpPost httppost = new HttpPost("/TRWebService/v1.1/trib.asmx");

    httppost.setHeader("Content-Type", "text/xml; charset=utf-8");
    httppost.setHeader("SOAPAction", "https://tempuri.org/GetPassword");

    StringEntity stringEntity = new StringEntity(soapMessage, "UTF-8");
    stringEntity.setChunked(true);
    httppost.setEntity(stringEntity);

    CloseableHttpResponse response = httpClient.execute(target, httppost, context);
}

感谢 SaopUI 解决了问题,它指导我找到了这个问题的原因。