如果我使用 HttpListener,如何将 WebException 304 错误模拟回浏览器?
那就是我收到了对我的 HttpListener 的请求,然后获得了 HttpListenerContext,那么从这一点开始,我将如何模仿/安排 HTTP“304 Not Modified”响应通过 HttpListenerContext.response 有效地发送回浏览器?
编辑:
我尝试了以下操作,但是尝试将 WebException.Status 复制到 HttpWebResponse.StatusCode 时出现错误(状态代码必须恰好是三位数)。关于如何纠正这个问题的任何想法?
catch (WebException ex)
{
listenerContext.Response.StatusCode = (int)ex.Status; //ERROR: The status code must be exactly three digits
listenerContext.Response.StatusDescription = ex.Message;
listenerContext.Response.Close();
谢谢