使用Windows.Web.Http.HttpClient NTLM身份验证

编程入门 行业动态 更新时间:2024-10-28 06:24:28
本文介绍了使用Windows.Web.Http.HttpClient NTLM身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我工作在Windows 10 UWP应用程序,需要与使用NTLM身份验证的IIS服务器。我设置的用户名和密码在HttpBaseProtocolFilter:

filter.ServerCredential =新PasswordCredential(URI,用户名,密码);

当我查看小提琴手的要求,它是使用基本认证。有什么我可以做的就是它使用NTLM,服务器所需要?

请求报头:

的Content-Length:1459内容类型:文本/ xml的;字符集= UTF-8主持人:服务器连接:保持活动缓存控制:无缓存饼干:客户端Id = XXXXXXXXX授权:基本XXXXXXXXX

响应头:

HTTP / 1.1 401匿名请求不允许服务器:Microsoft-IIS / 8.5请求ID:XXXXXWWW验证:NTLMWWW身份验证:协商的X已启动方式:ASP.NET的X FEServer:XXXXXXX日期:星期四,2015年12月3日16点12分58秒GMT内容长度:0代理服务器的支持:基于会话的验证

解决方案

简短的回答:NTLM身份验证不使用用户名/密码工作。需要重试连接的第二次,因为HttpClient的是pre-发送时服务器需要NTLM基本身份验证

龙答:我的应用程序托管的联系人在同一服务器上的两个服务。第一个允许基本认证,但第二只允许NTLM。首先,我连接到​​基本身份验证服务,然后我连接到NTLM之一。我将承担HttpClient的将自动拥有执行重试使用NTLM时,它得到了 WWW验证:NTLM 头,但现在看来,事实并非如此。但是,如果我手动重试连接,那么第二次的HttpClient将执行NTLM身份验证。

I am working on a Windows 10 UWP app that needs to talk to a IIS server using NTLM authentication. I am setting the username and password in the HttpBaseProtocolFilter:

filter.ServerCredential = new PasswordCredential(uri, UserName, Password);

When i view the request in fiddler, it is using Basic Auth. Is there anything I can do to get it to use NTLM, which the server is requiring?

Request Headers:

Content-Length: 1459 Content-Type: text/xml; charset=utf-8 Host: server Connection: Keep-Alive Cache-Control: no-cache Cookie: ClientId=XXXXXXXXX Authorization: Basic XXXXXXXXX

Response Headers:

HTTP/1.1 401 Anonymous Request Disallowed Server: Microsoft-IIS/8.5 request-id: xxxxx WWW-Authenticate: NTLM WWW-Authenticate: Negotiate X-Powered-By: ASP.NET X-FEServer: XXXXXXX Date: Thu, 03 Dec 2015 16:12:58 GMT Content-Length: 0 Proxy-Support: Session-Based-Authentication

解决方案

Short answer: NTLM auth does work with username / password. Need to retry the connection a second time, because HttpClient is pre-sending BASIC auth when server wants NTLM

Long answer: My app contacts two services hosted on the same server. The first allows Basic auth but the second only allows NTLM. First I connected to the Basic auth service and then I connect to the NTLM one. I would assume the HttpClient would have automatically performed a retry with NTLM when it got the WWW-Authenticate: NTLM header, but it appears that it doesn't. However, if I manually retry the connection, then the second time the HttpClient will perform NTLM auth.

更多推荐

使用Windows.Web.Http.HttpClient NTLM身份验证

本文发布于:2023-10-07 01:35:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1468069.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身份验证   Web   Windows   Http   NTLM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!