2011-11-07 33 views
0

今天我一直拉着我的頭髮與這個問題。我一直在開發一個內部應用程序,它執行一系列HTTP GET和POST以填充一系列Web表單。當我運行fiddler2時我的代碼工作正常 - 我用來調試我的GET URIs和POST FormData的工具。現在我沒有運行fiddler2我得到一個身份驗證401錯誤。我會查看標題進行比較,但是如果不能運行提琴手就有點困難。NTLM v1認證只適用於Fiddler2不是沒有

基本上我的代碼通過訪問URI並存儲cookie來工作。訪問該網站由SSO控制,並且服務器在2003年運行時,它希望使用NTLMv1。我在Windows 7客戶端遇到的第一個問題是Win7會協商128位,而服務器只會說64位,認證將失敗(最終401)。使用fiddler2並將本地計算機上的組策略設置爲64位,我就可以完成我的工作。然後,我把這個軟件變成了網絡服務,今天發現有一個問題在於它失敗了。正如我之前所說的,它在fiddler2運行正常的情況下工作正常,給我留下了一些漏洞,因爲我無法讓每個客戶端都安裝並使用fiddler2來獲得我的功能!

首先,我有我的功能來存儲Cookie ...。然後我有另一個功能,使用該cookie執行獲取第一個功能總是失敗,「遠程服務器返回錯誤:(401)未經授權。」

我希望某處我已經錯過了某些明顯的東西,我不想做一些不可能的事情。

感謝, 鋁

/// <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(); 
} 
+1

您是否嘗試過使用Wireshark運行?它將充當數據包捕獲,但不*代理。它應該讓你看到NTLM協商而不干擾它。 (它也做了很好的解碼NTLMSSP頭文件。) –

回答

0

我的解決方案是強制使用服務器上的NTLMv1 64位。不是我認識的每個人的解決方案,但它對我們有用。

1

我不知道答案至今,但我遇到同樣的問題,雖然有一些差異。如果沒有fiddler2運行,我也有一個失敗的進程,就像冠軍一樣。首先,我們有一個調度程序,它連接併發送原始Soap消息到各種Web服務,然後接收響應並將它們傳回數據庫。對於幾種服務,現在已經過了很長一段時間,通過這些外部服務的方式,這個過程一直在運行,沒有太多的東西。但是,當我們引入一個恰好在內部開發的Web服務時,我開始遇到完全相同的問題。

我最初懷疑的是,作爲代理人的提琴手以某種方式解決了證書問題。這可能會也可能不會,但它似乎是一個開始的好地方。首先,我迄今已檢測既:

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

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

沒有決心。另外,我已經使用

webRequest.Credentials = CredentialCache.DefaultCredentials; 

webRequest.Credentials = CredentialCache.DefaultNetworkCredentials; 

再次,沒有決心。我確實相信你對NTLMv1有了一些認識,我想我們可能需要以某種方式頒發NTLMv1身份驗證/授權證書。

微軟的網站指出: 爲authType的支持的值是 「NTLM」, 「文摘」, 「Kerberos的」 和 「協商」

The full story

這僅僅是一個在黑暗中拍攝,但這可能是服務器端的問題嗎?閱讀以下鏈接:http://support.microsoft.com/kb/813834

相關問題