我正在尝试为个人项目编写C#http服务器,我想知道如何将返回的服务器头从Microsoft-HTTPAPI/2.0更改为其他内容?
public class HttpWebServer { private HttpListener Listener; public void Start() { Listener = new HttpListener(); Listener.Prefixes.Add("http://*:5555/"); Listener.Start(); Listener.BeginGetContext(ProcessRequest, Listener); Console.WriteLine("Connection Started"); } public void Stop() { Listener.Stop(); } private void ProcessRequest(IAsyncResult result) { HttpListener listener = (HttpListener)result.AsyncState; HttpListenerContext context = listener.EndGetContext(result); string responseString = "Hello World"; byte[] buffer = Encoding.UTF8.GetBytes(responseString); context.Response.ContentLength64 = buffer.Length; System.IO.Stream output = context.Response.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); Listener.BeginGetContext(ProcessRequest, Listener); } }
arul.. 9
HttpListener类封装了本机API,HttpSendHttpResponse函数,如链接中所述,它将始终将荒谬的文本附加到服务器头信息中.
除非你想从头编写你的HttpListener,否则无法解决这个问题.
HttpListener类封装了本机API,HttpSendHttpResponse函数,如链接中所述,它将始终将荒谬的文本附加到服务器头信息中.
除非你想从头编写你的HttpListener,否则无法解决这个问题.
我知道我有点晚了,但我最近才尝试做同样的事情,我偶然遇到了一个有效的解决方案,但我不确定它是否有任何影响.
Response.Headers.Add("Server", "\r\n\r\n");