當前位置: 首頁>>代碼示例>>C#>>正文


C# HttpListenerResponse.CopyFrom方法代碼示例

本文整理匯總了C#中System.Net.HttpListenerResponse.CopyFrom方法的典型用法代碼示例。如果您正苦於以下問題:C# HttpListenerResponse.CopyFrom方法的具體用法?C# HttpListenerResponse.CopyFrom怎麽用?C# HttpListenerResponse.CopyFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。


在下文中一共展示了HttpListenerResponse.CopyFrom方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SendBadCertificateResponse

static string message403;
static HttpListenerResponse preMade403Response;
static void SendBadCertificateResponse(HttpListenerResponse response)
{
    if (preMade403Response == null)
    {
        // Set up an authentication error response template.
        response.StatusCode = (int)HttpStatusCode.Forbidden;
        response.StatusDescription = "403 Forbidden";
        response.ProtocolVersion = new Version("1.1");
        response.SendChunked = false;

        preMade403Response = response;
    }
    else
    {
        response.CopyFrom(preMade403Response);
    }

    // The response body cannot be saved in the template.

    StringBuilder message = new StringBuilder();
    message.Append("<HTML><BODY>");
    message.Append("<p> Error message 403: Access is denied due to a missing or invalid client certificate.</p>");
    message.Append("</BODY></HTML>");
    message403 = message.ToString();

    // Turn the error message into a byte array using the 
    // encoding from the response when present.
    System.Text.Encoding encoding = response.ContentEncoding;
    if (encoding == null)
    {
        encoding = System.Text.Encoding.UTF8;
        response.ContentEncoding = encoding;
    }

    byte[] buffer = encoding.GetBytes(message403);
    response.ContentLength64 = buffer.Length;
    // Write the error message.
    System.IO.Stream stream = response.OutputStream;
    stream.Write(buffer, 0, buffer.Length);
    // Send the response.
    response.Close();
}
開發者ID:.NET開發者,項目名稱:System.Net,代碼行數:44,代碼來源:HttpListenerResponse.CopyFrom


注:本文中的System.Net.HttpListenerResponse.CopyFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。