繁体   English   中英

NTLM v1身份验证仅适用于Fiddler2,而不能不使用

[英]NTLM v1 authentication only works with Fiddler2 not without

今天我一直在努力解决这个问题。 我一直在开发一个内部应用程序,该应用程序执行一系列HTTP GET和POST来填充一系列Web表单。 通过fiddler2(我用来调试GET URI和POST FormData的工具)运行时,代码工作正常。 现在我没有运行fiddler2,但收到身份验证401错误。 我会看一下标头进行比较,但是如果无法运行提琴手,这会有些困难。

基本上,我的代码通过访问URI并存储cookie来工作。 对站点的访问由SSO控制,并且由于服务器在2003年上运行,因此它想使用NTLMv1。 我在Windows 7客户端上遇到的第一个问题是Win7将协商128位,而服务器将仅协商64位,并且身份验证将失败(最终401)。 使用fiddler2并将本地计算机上的组策略设置为64位,我便可以完成我的工作。 然后,我将软件转换为Web服务,发现今天存在一个问题,那就是它失败了。 就像我之前说过的那样,在fiddler2运行时一切正常,因为我无法让每个客户端都安装和使用fiddler2只是为了获得我的功能,所以这让我有些麻烦!

首先,我具有存储cookie的功能。 然后,我还有另一个函数使用该cookie执行获取操作,第一个函数总是失败,并显示“远程服务器返回错误:(401)未经授权。”

我希望在某个地方错过了一些显而易见的事情,而我并不是想做一些不可能的事情。

谢谢Al

/// <summary>
/// Function to get a cookie from a site providing the given site and credentials - this cookie then can be reused for subsequent calls
/// </summary>
/// <param name="credential">The NetworkCredential to access the site</param>
/// <param name="Uri">The Uri of the site</param>
/// <returns>A CookieContainer containing all needed cookies</returns>
private CookieContainer GetCookie(NetworkCredential credential, string Uri)
{
    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(Uri);
    HttpWebResponse resp;
    CookieContainer cookieJar = new CookieContainer();
    req.AllowAutoRedirect = true;
    req.Credentials = credential;
    req.CookieContainer = cookieJar;
    resp = (HttpWebResponse)req.GetResponse();      // This line always fails with: The remote server returned an error: (401) Unauthorized.
    return cookieJar;
}

/// <summary>
/// Function to perform a HTTP GET 
/// </summary>
/// <param name="cookieJar">A CookieContainer for keeping the reference of our sessions</param>
/// <param name="credential">The Credentials to use to access the site</param>
/// <param name="Uri">The Uri to GET</param>
private void DoGet(CookieContainer cookieJar, NetworkCredential credential, string Uri)
{
    HttpWebRequest req;
    HttpWebResponse resp;

    // Just grab the site uri where the cookie is stored
    string[] UriParts = Uri.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
    Uri CookieUri = new Uri(UriParts[0] + "//" + UriParts[1]);

    // Use cookie information to get first page of call entry
    req = (HttpWebRequest)HttpWebRequest.Create(Uri);
    req.CookieContainer = new CookieContainer();
    req.CookieContainer.Add(cookieJar.GetCookies(CookieUri)[0]);
    req.AllowAutoRedirect = true;
    req.Credentials = credential;
    req.CookieContainer = cookieJar;
    resp = (HttpWebResponse)req.GetResponse();
}

我尚不知道答案,但我遇到了相同的问题,尽管有一些不同。 我也有一个没有fiddler2运行就失败的进程,它的工作原理就像冠军。 首先,我们有一个调度程序应用程序,该应用程序连接到各种Web服务并将原始Soap消息发送到各种Web服务,然后接收响应并将它们传递回数据库。 对于一些服务而言,并且在相当长的一段时间内,这些服务都是外部服务,该过程一直运行得很顺利。 但是,当我们引入恰好是内部开发的Web服务时,我开始遇到完全相同的问题。

我首先怀疑的是,提琴手作为代理人以某种方式解决了凭证问题。 这可能会或可能不会,但似乎是一个不错的起点。 首先,到目前为止,我已经对两者进行了测试:

IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();

没有决心。 另外,我用过

webRequest.Credentials = CredentialCache.DefaultCredentials;

webRequest.Credentials = CredentialCache.DefaultNetworkCredentials;  

再次,没有决心。 我确实相信您对NTLMv1有所了解,并且我认为我们可能需要以某种方式颁发NTLMv1身份验证/授权的凭据。

Microsoft的网站状态:authType支持的值为“ NTLM”,“摘要”,“ Kerberos”和“协商”

全文

这只是黑暗中的一枪,但这可能是服务器端的问题吗? 阅读以下链接: http : //support.microsoft.com/kb/813834

我的解决方案是强制在服务器上使用NTLMv1 64位。 这不是我认识的每个人的解决方案,但对我们有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM