Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   HttpWebRequest & (401) Unauthorized http status code (http://www.velocityreviews.com/forums/t80989-httpwebrequest-and-401-unauthorized-http-status-code.html)

=?Utf-8?B?UG1jZw==?= 06-21-2004 12:55 PM

HttpWebRequest & (401) Unauthorized http status code
 
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;


try
{
// 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.UTF8);
_strResponse = _ResponseStreamReader.ReadToEnd();

// Close response stream
_ResponseStream.Close();

// Write out response
Console.WriteLine(_strResponse);
}
catch (Exception GenericException)
{
Console.WriteLine(GenericException.Message);
}
}




Thanks in advance
Pat


All times are GMT. The time now is 03:04 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.