gpt4 book ai didi

java - 使用 NTLM 身份验证使用 soap 服务

转载 作者:搜寻专家 更新时间:2023-11-01 03:48:08 24 4
gpt4 key购买 nike

我正在尝试通过创建一个 NTLM 引擎(按照 http://hc.apache.org/httpcomponents-client-4.3.x/ntlm.html 上的说明)使用带有 NTLM 身份验证的 SOAP 服务,实现 AuthSchemeFactory 并最终将 AuthSchemeFactory 注册到我的 HTTP 客户端。当我使用我的 HTTP 客户端访问服务时,我得到一个响应“状态代码 - 415,消息 - 服务器无法为请求提供服务,因为媒体类型不受支持。”

谁能告诉我如何解决这个不受支持的媒体问题,以便在 Java 平台上使用受 NTLM 保护的 SOAP Web 服务。使用 JCIFS 是使用 NTLM 保护服务的正确选项还是有更好的方法。提前致谢。

    DefaultHttpClient httpclient = new DefaultHttpClient();

httpclient.getAuthSchemes().register(AuthSchemes.NTLM,
new JCIFSNTLMSchemeFactory());

CredentialsProvider credsProvider = new BasicCredentialsProvider();
NTCredentials ntcred = new NTCredentials("USERNAME", "PASSWORD",
"HOST", "DOMAIN");

credsProvider.setCredentials(new AuthScope("HOST", 443,
AuthScope.ANY_REALM, "NTLM"), ntcred);

httpclient.setCredentialsProvider(credsProvider);

httpclient.getParams().setParameter(
CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");

Writer writer = new StringWriter();
writer.write("MY SOAP REQUEST BODY");

HttpPost httppost = new HttpPost(
"https://<HOST_NAME>/XiPay30WS.asmx");
httppost.setEntity(new StringEntity(writer.toString()));

httppost.setHeader("Content-Type",
"application/x-www-form-urlencoded");

HttpResponse httpresponse = httpclient.execute(
new HttpHost("HOST", 443, "https"),
httppost, new BasicHttpContext());

String statusCode = httpresponse.getStatusCode();

最佳答案

如果你使用 Spring WS 支持:

检查这个解决方案 http://dolszewski.com/spring/sharepoint-web-services-spring-and-ntlm-authentication/

@Bean("navisionMessageSender")
public HttpComponentsMessageSender httpComponentsMessageSender() {
HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender();
String user = env.getProperty("navision.endpoint.user");
String password = env.getProperty("navision.endpoint.password");
String domain = env.getProperty("navision.endpoint.domain");
NTCredentials credentials = new NTCredentials(user, String.valueOf(password), null, domain);
httpComponentsMessageSender.setCredentials(credentials);
return httpComponentsMessageSender;
}

关于java - 使用 NTLM 身份验证使用 soap 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37660995/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com