Checking whether the WebRequest is authorised or not in ASP.NET
<p>I am creating a webrequest using WEBRequest Object (with METHOD POST) </p>

<p>The problem is i want to check whether the request is authorised as if i try to pass the wrong credentials the response is UNAUTHORISED</p>

<p>So how can i check without using some try catch.</p>

<p>CODE:</p>

<pre><code> HttpWebRequest request = (HttpWebRequest)
        WebRequest.Create("http://......");

        request.Credentials = new NetworkCredential("test@yahoo.com.au", "pwd");

        request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        request.Method = "POST";

        byte[] postBytes = Encoding.ASCII.GetBytes(post_data);

        request.ContentType = "application/xml";

        request.ContentLength = postBytes.Length;
        Stream requestStream = request.GetRequestStream();

        // now send it
        requestStream.Write(postBytes, 0, postBytes.Length);
        requestStream.Close();

        try
        {
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
            Console.WriteLine(response.StatusCode);
        }
        catch (Exception ex)
        {

        }
</code></pre>

<p>Any help is appreciated</p>
