I’m trying to post to an asp.net webpage and receive the resulting xml.
Here’s my code:
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();
When I run this, I get an HTTP Error 401.2 error explaining: You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.
When using the asp.net page on the website, this is the header info I get in 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
With this Auth info:
- No Proxy-Authenticate Header is present.
- No WWW-Authenticate Header is present.
When running my application, this is the header info I get in 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
With this Auth info:
- No Proxy-Authenticate Header is present.
- WWW-Authenticate Header is present: Basic realm=”www.dmr.nd.gov”
How do I avoid that WWW-Authenticate Header being pushed over?
After further investigation, I figured out the authentication issue wasn’t really my problem. Apparently I wanted a GET operation, and I was running a POST operation.