【发布时间】:2017-04-20 15:57:10
【问题描述】:
我正在使用 Apache HttpClient 4.5.3 版从 Web 服务 (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);
}
【问题讨论】:
-
由于 HTTP 500 响应代码指示服务器端错误,如果您有访问它。
-
我不认为这是服务器端错误,因为使用另一个用 Ruby 编写的程序,一切正常。我没有访问服务器的权限
-
听起来您发送的输入不正确,而服务器遇到了问题——这正是 500 响应的含义。我建议将您发送到服务器的内容与 Ruby 应用程序发送的内容进行比较。
-
我已经比较了它们,但似乎没有什么不同
标签: java apache-httpclient-4.x ntlm