473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Nov 18 '05 #1
0 2361

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
0
by: Cozfer | last post by:
I am having a problem communicating with a remote server (on intranet) using the httpwebrequest object. We have used the object to communicate with other machines previously, but this time we must...
8
by: Noel Volin | last post by:
Anyone who can help here is much appreciated. I am trying to programmatically log onto a website. I am using the code provided in VS for the AuthenticationManager Class example (...
2
by: Steve Richter | last post by:
I have a page that uses simple HTTP GET to do an ISBN lookup via Amazon.com. The page works when I run it from //localhost. But I have moved it to my godaddy.com shared hoster site, and I get...
2
by: Greg | last post by:
I've been reading a lot of other posts and trying a bunch of things but just cannot get this to work. I'm hoping someone can help. Here's the situation. I have a test folder which only...
2
by: Greg | last post by:
I've been reading a lot of other posts and trying a bunch of things but just cannot get this to work. I'm hoping someone can help. Here's the situation. I have a test folder which only...
2
by: Iain Adams | last post by:
I currently have a web service set that returns data. When I use these services through a browser, everything works fine and the resulting xml is displayed. However sometimes when I connect to the...
2
by: =?Utf-8?B?TGFycnlLdXBlcm1hbg==?= | last post by:
Our WebDev team seems to have found a problem that exposes a bug in .NET 2.0. This problem can be shown when trying to access a WebService using SSL and through a proxy server after using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.