从ASP.NET服务发送Windows身份验证的请求
我有一个工作的Python脚本,该脚本将请求使用Windows身份验证发送到Web服务,以获取令牌。
我要复制的位是:
url = 'https://ssologin.company.com/Logon/Logon.aspx?permission=permission'
h = WC.Dispatch('WinHTTP.WinHTTPRequest.5.1')
h.SetAutoLogonPolicy(0)
h.SetOption(6, False)
h.Open('GET', url, False)
h.Send()
我有一个ASP.NET核心服务,试图这样做:
var uri = new Uri("https://ssologin.company.com/Logon/Logon.aspx?permission=permission");
WinHttpHandler handler = new WinHttpHandler();
handler.ServerCredentials = CredentialCache.DefaultNetworkCredentials;
HttpClient httpClient = new HttpClient(handler);
var httpResponseMessage = await httpClient.GetAsync(uri);
现在,我收到以下错误: winhttpexception:错误12029调用winhttp_callback_status_request_error,“无法建立与服务器的连接”。
但是,如果我注释// Handler.ServerCredentials = recredentialCache.defaultNetworkCredentials;
,那么我将获得错误401未经授权。我还注意到recredentialcache.defaultnetworkcredentials是无效的。
你能让我知道我在这里缺少什么吗?谢谢。
I have a working Python script which sends a request to an web service using Windows Authentication in order to get a token.
The bit that I'm trying to replicate is:
url = 'https://ssologin.company.com/Logon/Logon.aspx?permission=permission'
h = WC.Dispatch('WinHTTP.WinHTTPRequest.5.1')
h.SetAutoLogonPolicy(0)
h.SetOption(6, False)
h.Open('GET', url, False)
h.Send()
I have an ASP.NET Core service which tries to do it this way:
var uri = new Uri("https://ssologin.company.com/Logon/Logon.aspx?permission=permission");
WinHttpHandler handler = new WinHttpHandler();
handler.ServerCredentials = CredentialCache.DefaultNetworkCredentials;
HttpClient httpClient = new HttpClient(handler);
var httpResponseMessage = await httpClient.GetAsync(uri);
Right now I am getting the following error:
WinHttpException: Error 12029 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, 'A connection with the server could not be established'.
However, if I comment // handler.ServerCredentials = CredentialCache.DefaultNetworkCredentials;
, then I get Error 401 Unauthorised. I also noticed that CredentialCache.DefaultNetworkCredentials is NULL.
Can you please let me know what I am missing here? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,身份验证工作正常,但是请求将其重定向到拒绝连接的服务。简单的解决方法是仅禁用重定向。另外,在 @spzvtbg的建议下,我使用了默认的
httpclienthandler
。最终代码最终以这样的方式:
Actually, the authentication worked fine, but the request was redirecting to a service which refuses to connect. The easy fix to this was to just disable redirecting. Also, at @spzvtbg's suggestion, I used the default
HttpClienthandler
.The final code ended up like this: