[英]HTTP Error 401.2 When Issuing HttpRequest
我正在尝试发布到asp.net网页并接收生成的xml。
这是我的代码:
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页面时,这是我在Fiddler中获得的标题信息:
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
使用此身份验证信息:
运行我的应用程序时,这是我在Fiddler中获得的标题信息:
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
使用此身份验证信息:
如何避免将WWW身份验证标头推入?
经过进一步调查,我发现身份验证问题并不是我的问题。 显然我想要GET操作,而我正在运行POST操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.