HttpWebRequest & (401) Unauthorized http status code

Discussion in 'ASP .Net' started by =?Utf-8?B?UG1jZw==?=, Jun 21, 2004.

  1. 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
    =?Utf-8?B?UG1jZw==?=, Jun 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sachin
    Replies:
    2
    Views:
    17,885
    Sachin
    Nov 4, 2005
  2. ad
    Replies:
    2
    Views:
    13,513
  3. ad
    Replies:
    0
    Views:
    1,618
  4. emily li via .NET 247

    HTTP status 401: Unauthorized in SC Win98se

    emily li via .NET 247, Oct 17, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    140
    emily li via .NET 247
    Oct 17, 2004
  5. emily li via .NET 247

    HTTP status 401: Unauthorized in SC Win98se

    emily li via .NET 247, Oct 31, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    156
    emily li via .NET 247
    Oct 31, 2004
Loading...

Share This Page