使用 HTTP Web 请求发送 HTTP 标头以进行 NTLM 身份验证 [英] Sending HTTP Headers with HTTP Web Request for NTLM Authentication

查看:28
本文介绍了使用 HTTP Web 请求发送 HTTP 标头以进行 NTLM 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想登录 Sharepoint 门户,该门户会显示登录对话框但使用的是 NTLM 身份验证.如何修改 C# 中的 HTTP 标头以发出成功的登录请求?我假设我需要向门户登录部分中的页面发出 HTTPWebRequest 并在此旁边发布 HTTP 标头集合?

I want to login to a Sharepoint portal which brings up a login dialog but is using NTLM authentication. How can I modify the HTTP headers in C# to make a successful login request? I assume I would need to make a HTTPWebRequest to a page within the logged in section of the portal and post the HTTP headers collection alongside this?

推荐答案

您可以使用 WebRequest 类来做到这一点.

You can do this using the WebRequest class.

WebRequest req = WebRequest.Create(tokenUri);
req.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested;
req.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
WebResponse resp = req.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream());
var token = reader.ReadToEnd().Trim();

这段代码将整个响应读入一个名为token的变量中.

This code reads the whole response into a variable called token.

这篇关于使用 HTTP Web 请求发送 HTTP 标头以进行 NTLM 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆