.net HttpListener为带有尾随点的主机返回400个错误请求

.net HttpListener为带有尾随点的主机返回400个错误请求,.net,httplistener,.net,Httplistener,如果主机头包含带有尾随点的主机名,则HttpListener类将返回状态400“Bad Request” 代码(基于): 有没有办法配置HttpListener,使“localhost”和“localhost.”请求得到同样好的服务 using System.Text; using System.Net; namespace HttpListenerTest { class Program { static void Main(string[] args)

如果主机头包含带有尾随点的主机名,则HttpListener类将返回状态400“Bad Request”

代码(基于):

有没有办法配置HttpListener,使“localhost”和“localhost.”请求得到同样好的服务

using System.Text;
using System.Net;

namespace HttpListenerTest
{
    class Program
    {
        static void Main(string[] args)
        {
            SimpleListenerExample(new []{"http://*:8081/"});
        }

        public static void SimpleListenerExample(string[] prefixes)
        {
            var listener = new HttpListener();
            foreach (var s in prefixes)
                listener.Prefixes.Add(s);
            listener.Start();
            while (true)
            {
                var context = listener.GetContext();
                var response = context.Response;
                var buffer = Encoding.UTF8.GetBytes("<HTML><BODY> Hello world!</BODY></HTML>");
                response.ContentLength64 = buffer.Length;
                var output = response.OutputStream;
                output.Write(buffer, 0, buffer.Length);
                output.Close();
            }
        }
    }
}
Error 400:
c:\...> curl -v --header "Host: localhost.local." http://localhost.:17320/
c:\...> curl -v --header "Host: localhost." http://localhost.:17320/

OK 200:
c:\...> curl -v --header "Host: localhost.local" http://localhost.:17320/
c:\...> curl -v --header "Host: localhost" http://localhost.:17320/