Java Apache HttpClient-NTLM:500内部服务器错误
我正在使用ApacheHttpClient版本4.5.3从Web服务(MicrosoftIIS/8.5)获取一些信息 因此需要NTLM身份验证。但在这个过程结束时,我收到了500个内部服务器错误,尽管一切似乎都很正常(发送messagetype1、接收挑战、发送messagetype3) 下面是代码,如果您能提供一些帮助来解决此错误,则表示感谢Java Apache HttpClient-NTLM:500内部服务器错误,java,apache-httpclient-4.x,ntlm,Java,Apache Httpclient 4.x,Ntlm,我正在使用ApacheHttpClient版本4.5.3从Web服务(MicrosoftIIS/8.5)获取一些信息 因此需要NTLM身份验证。但在这个过程结束时,我收到了500个内部服务器错误,尽管一切似乎都很正常(发送messagetype1、接收挑战、发送messagetype3) 下面是代码,如果您能提供一些帮助来解决此错误,则表示感谢 String workstation = "someurl.com"; String domain ="DOMBIN"; String userName
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);
}
String workstation=“someurl.com”;
String domain=“DOMBIN”;
字符串userName=“KSY5989”;
字符串soapMessage=“”+
""+
""+
""+
""+
“用户658”+
“someurl.com”+
"60"+
""+
""+
""+
"";
SSLContext SSLContext=SSLContexts
.custom()
//修复包含真实信任存储的问题
.loadTrustMaterial(新信任策略)(){
公共布尔isTrusted(X509Certificate[]链,字符串authType)引发CertificateException{
//TODO自动生成的方法存根
返回true;
}
})
.build();
Registry authSchemeRegistry2=RegistryBuilder.create()
.register(AuthSchemes.NTLM,新的NTLMSchemeFactory())
.build();
NTCredentials=新的NTCredentials(用户名、密码、工作站、域);
CredentialsProvider credsProvider=新的BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,credentials);
try(CloseableHttpClient httpClient=HttpClients.custom().setDefaultAuthSchemeRegistry(authSchemeRegistry2).setSSLContext(sslContext).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()){
HttpHost target=newHttpHost(“someurl.net”,5489,“https”);
HttpClientContext=HttpClientContext.create();
context.setCredentialsProvider(credProvider);
HttpPost-HttpPost=newhttppost(“/TRWebService/v1.1/trib.asmx”);
setHeader(“内容类型”,“text/xml;charset=utf-8”);
setHeader(“SOAPAction”https://tempuri.org/GetPassword");
StringEntity StringEntity=新的StringEntity(soapMessage,“UTF-8”);
stringEntity.setChunked(true);
httppost.setEntity(stringEntity);
CloseableHttpResponse response=httpClient.execute(目标、httppost、上下文);
}
由于SaopUI指导我找到了问题的原因,问题得以解决。由于HTTP 500响应代码表明存在服务器端错误,因此在web服务端跟踪此错误可能会更容易(找出服务器端错误是什么),我不认为这是一个服务器端错误,因为有了另一个用Ruby编写的程序,一切都很好。我没有访问服务器的权限听起来你发送了错误的输入,服务器遇到了问题-这正是500响应的意思。我建议您将发送到服务器的内容与Ruby应用程序发送的内容进行比较。我已经对它们进行了比较,但似乎没有什么不同