Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HttpWebRequest & (401) Unauthorized http status code

Thread Tools

HttpWebRequest & (401) Unauthorized http status code

Posts: n/a
I would appreciate any help with the following, havn't found any answers for this in my research to date.

I am trying to retreive a web page (a htm file intially) from a vdir on an intranet site using the following code, where the vdir has "Integrated Windows authentication" turned on but "Anonymous access" turned off, i get the following message
The remote server returned an error: (401) Unauthorized.
If i use the browser i can see the page with no problems.
If i enable "Anonymous access", the below will work but this completly defeats the purpose of turning on "Integrated Windows authentication".
I have seen web posts where people using some COM components in VB6.0 can get this to work but for some reason the HttpWebRequest being used below will not work event though i have set the PreAuthenticate property.

private static void HttpGet(string strUrl)
HttpWebRequest _Request = null;
HttpWebResponse _Response = null;
Stream _ResponseStream = null;
StreamReader _ResponseStreamReader = null;
string _strResponse = string.Empty;

// Instantiate request setting header properties
_Request = (HttpWebRequest) WebRequest.Create(strUrl);
_Request.Method = "GET";
_Request.ContentType = "text/xml";

// Proxy
_Request.PreAuthenticate = true;
_Request.Proxy = WebProxy.GetDefaultProxy();
_Request.Proxy.Credentials = CredentialCache.DefaultCredentials;

// Get response
_Response = (HttpWebResponse) _Request.GetResponse();
_ResponseStream = _Response.GetResponseStream();
_ResponseStreamReader = new StreamReader(_ResponseStream, Encoding.UTF;
_strResponse = _ResponseStreamReader.ReadToEnd();

// Close response stream

// Write out response
catch (Exception GenericException)

Thanks in advance
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with ReportingService.Credentials - Syste.Net.WebException - "The request failed with HTTP status 401: Unauthorized." Shree ASP .Net 0 09-02-2006 07:33 PM
The request failed with HTTP status 401: Unauthorized ad ASP .Net 2 02-18-2006 12:11 AM
The request failed with HTTP status 401: Unauthorized ad ASP .Net 0 02-17-2006 06:14 AM
The request failed with HTTP status 401: Unauthorized Sachin ASP .Net 2 11-04-2005 09:15 PM
HTTP status 401: Unauthorized in SC Win98se emily li via .NET 247 ASP .Net Web Services 0 10-17-2004 10:04 AM