本文整理汇总了C#中HttpServerResponse.WriteHead方法的典型用法代码示例。如果您正苦于以下问题:C# HttpServerResponse.WriteHead方法的具体用法?C# HttpServerResponse.WriteHead怎么用?C# HttpServerResponse.WriteHead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.WriteHead方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnHttpServerRequest
private void OnHttpServerRequest(HttpServerRequest httpRequest, HttpServerResponse httpResponse)
{
UrlData urlData = Url.Parse(httpRequest.Url, /* parseQueryString */ true);
ServerRoute route = _router.Match(urlData.PathName);
Action<Exception> errorHandler = delegate(Exception e) {
httpResponse.WriteHead(HttpStatusCode.InternalServerError, e.Message);
httpResponse.End();
Runtime.TraceInfo("500 : %s %s", httpRequest.Method, httpRequest.Url);
return;
};
ServerRequest request = new ServerRequest(httpRequest, urlData, route);
Task<ServerResponse> responseTask = null;
try {
responseTask = _modules[0].ProcessRequest(request);
}
catch (Exception e) {
errorHandler(e);
return;
}
responseTask.Done(delegate(ServerResponse response) {
response.Write(httpResponse);
Runtime.TraceInfo("%d : %s %s", response.StatusCode, httpRequest.Method, httpRequest.Url);
})
.Fail(errorHandler);
}
示例2: Write
internal void Write(HttpServerResponse httpResponse)
{
httpResponse.WriteHead(_statusCode, _headers);
if (_content != null) {
httpResponse.Write(_content, Encoding.UTF8);
}
httpResponse.End();
}