public void SendError(string msg, int status) { try { HttpListenerResponse response = context.Response; response.StatusCode = status; response.ContentType = "text/html"; string description = HttpListenerResponse.GetStatusDescription(status); string str; if (msg != null) { str = String.Format("<h1>{0} ({1})</h1>", description, msg); } else { str = String.Format("<h1>{0}</h1>", description); } byte [] error = context.Response.ContentEncoding.GetBytes(str); response.Close(error, false); } catch { // response was already closed } }
public void SendError(string msg, int status) { try { HttpListenerResponse response = context.Response; response.StatusCode = status; response.ContentType = "text/html"; string statusDescription = HttpListenerResponse.GetStatusDescription(status); string s = (msg == null) ? $"<h1>{statusDescription}</h1>" : $"<h1>{statusDescription} ({msg})</h1>"; byte[] bytes = context.Response.ContentEncoding.GetBytes(s); response.Close(bytes, willBlock: false); } catch { } }
public void SendError(string msg, int status) { try { HttpListenerResponse response = this.context.Response; response.StatusCode = status; response.ContentType = "text/html"; string statusDescription = HttpListenerResponse.GetStatusDescription(status); string s; if (msg != null) { s = string.Format("<h1>{0} ({1})</h1>", statusDescription, msg); } else { s = string.Format("<h1>{0}</h1>", statusDescription); } byte[] bytes = this.context.Response.ContentEncoding.GetBytes(s); response.Close(bytes, false); } catch { } }