HttpListenerResponse.StatusCode HttpListenerResponse.StatusCode HttpListenerResponse.StatusCode HttpListenerResponse.StatusCode Property

定義

取得或設定傳回至用戶端的 HTTP 狀態碼。Gets or sets the HTTP status code to be returned to the client.

public:
 property int StatusCode { int get(); void set(int value); };
public int StatusCode { get; set; }
member this.StatusCode : int with get, set
Public Property StatusCode As Integer

屬性值

Int32 值,指定所要求之資源的 HTTP 狀態碼。An Int32 value that specifies the HTTP status code for the requested resource. 預設值為 OK,指出伺服器成功處理用戶端的要求,並在回應主體中包含所要求的資源。The default is OK, indicating that the server successfully processed the client's request and included the requested resource in the response body.

例外狀況

指定給設定作業的值無效。The value specified for a set operation is not valid. 有效值介於 100 和 999 (含) 之間。Valid values are between 100 and 999 inclusive.

範例

下列程式碼範例將示範如何設定這個屬性的值。The following code example demonstrates setting the value of this property.

public static string[] CopyPrefixes (HttpListener listener)
{
     HttpListenerPrefixCollection prefixes = listener.Prefixes;
     string[] prefixArray = new string[prefixes.Count];
     prefixes.CopyTo(prefixArray, 0);
     return prefixArray;
}
Public Shared Function CopyPrefixes(ByVal listener As HttpListener) As String()
    Dim prefixes As HttpListenerPrefixCollection = listener.Prefixes
    Dim prefixArray As String() = New String(prefixes.Count - 1) {}
    prefixes.CopyTo(prefixArray, 0)
    Return prefixArray
End Function

備註

用戶端會使用由伺服器傳回狀態碼,決定要如何繼續進行。Clients use the status code returned by the server to decide how to proceed. 值為OK表示伺服器已成功處理用戶端的要求,並在回應主體中包含所要求的資源。A value of OK indicates that the server successfully processed the client's request and included the requested resource in the response body. 其他常見狀態碼包含NotFound,指出在伺服器上,找不到要求的資源和NotModified,表示這不必要的回應主體中傳回要求的資源,因為用戶端的快取的複本資源是最新狀態。Other common status codes include NotFound, indicating that the requested resource was not found on the server, and NotModified, indicating that it was unnecessary to return the requested resource in the response body because the client's cached copy of the resource is up-to-date.

如需可能的狀態碼的完整清單,請參閱HttpStatusCode列舉型別。For a complete list of possible status codes, see the HttpStatusCode enumeration.

適用於

另請參閱