0
我試圖張貼到一個asp.net網頁,並收到產生的XML。HTTP錯誤401.2當頒發HttpRequest
這裏是我的代碼:
Uri url = new Uri("https://www.dmr.nd.gov/oilgas/feeservices/getcpfilesxml.asp");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Credentials = nc;
request.Method = "POST";
Byte[] postBuffer = Encoding.UTF8.GetBytes("FileNumber=04113");
request.ContentLength = postBuffer.Length;
request.ContentType = "text/xml; Charset=UTF-8";
using (Stream postData = request.GetRequestStream())
{
postData.Write(postBuffer, 0, postBuffer.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
當我運行它,我得到一個HTTP錯誤401.2錯誤解釋:您沒有權限使用您提供,因爲您的Web瀏覽器的憑據查看該目錄或網頁正在發送Web服務器未配置爲接受的WWW-Authenticate標頭字段。
當使用網站上的asp.net頁面,這是標題信息,我在小提琴手得到:
HTTP/1.1 200 OK
Date: Tue, 01 May 2012 15:34:44 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 4325
Content-Type: text/xml; Charset=UTF-8
Cache-control: private
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
有了這個身份驗證信息:
- 沒有Proxy-Authenticate頭存在。
- 否WWW-Authenticate Header存在。
當運行我的應用程序,這是標題信息,我在小提琴手得到:
HTTP/1.1 200 OK
Date: Tue, 01 May 2012 17:18:04 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Content-Length: 124
Content-Type: text/xml; Charset=UTF-8
Cache-control: private
Set-Cookie: ASPSESSIONIDASADTBCS=JEBNCDNDNEPNLEBIEAFHENJF; path=/
X-Pad: avoid browser bug
有了這個身份驗證信息:
- 沒有Proxy-Authenticate頭是存在的。
- WWW身份驗證標頭是存在:基本境界=「www.dmr.nd.gov」
如何避免WWW身份驗證頭被推向了嗎?
'request.Credentials = nc;'中的'nc'是什麼? –
我將證書與請求一起傳遞,但爲了保護隱私,我將其從帖子中移除。對困惑感到抱歉。 – John
但是,如果你想避免WWW-Authenticate頭部,你爲什麼要這樣做呢?他們是相關的... –