Description





Description

This enumeration is used by HttpWebResponse.

[Note: The HttpStatusCode enumeration contains the values of the status codes defined in IETF RFC 2616 - HTTP/1.1. The status of an HTTP request is contained in the HttpWebResponse.StatusCode property.]

Example

Figure

The following example compares the status returned by an HttpWebResponse with an HttpStatusCode value to determine the status of the response.


using System;

using System.Net;



public class HttpStatusCodeExample 

{



    public static void Main() 

    {

        string serverName = "http://www.contoso.com";

        HttpWebRequest httpReq = (HttpWebRequest) WebRequest.Create(serverName);

        httpReq.AllowAutoRedirect = false;

        HttpWebResponse httpRes = (HttpWebResponse) httpReq.GetResponse();

        if (httpRes.StatusCode==HttpStatusCode.Found) 

        {    

            Console.WriteLine("Request for {0} was redirected.", serverName);

        }

    }

}


The output is

Request for http://www.contoso.com was redirected.


Figure


using System;

using System.Net;





public class HttpStatusCodeSample

{

    public static void Main()

    {

        HttpWebRequest req = (HttpWebRequest)

            WebRequest.Create("http://microsoft.com");

        HttpWebResponse result = (HttpWebResponse)req.GetResponse();

        Console.WriteLine("HttpWebResponse.StatusCode = {0}",

            result.StatusCode);

    }

}


The output is

HttpWebResponse.StatusCode = OK



     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows