2011-02-03 12 views
7

किसी कारण से जब अनुरोध गैर standart पते के माध्यम से HttpListener को भेजा जाता है यह रिटर्नसी # HttpListener 'गलत अनुरोध' समस्या

<h1>Bad Request (Invalid Hostname)</h1> 

उदाहरण पैकेट:

GET /index HTTP/1.1 
Host: ::ffff:88.118.32.126:2548 
Accept: */* 

HTTP/1.1 400 Bad Request 
Content-Type: text/html 
Server: Microsoft-HTTPAPI/1.0 
Date: Wed, 02 Feb 2011 19:05:18 GMT 
Connection: close 
Content-Length: 39 

<h1>Bad Request (Invalid Hostname)</h1> 

मैं यह कैसे हल कर सकते थे?

संपादित करें: यह मेरा कोड

public class Server 
{ 
    private HttpListener Listener; 
    private Log Log; 

    public int Port = 1555; 

    public Server(Log _log) 
    { 
     Log = _log; 
    } 

    public void Start() 
    { 
     Listener = new HttpListener(); 
     Listener.Prefixes.Add(string.Format("http://{0}:{1}/", 
      "88.118.32.126", Port)); 

     Listener.Prefixes.Add(
      string.Format("http://{0}:{1}/", 
      "*", Port)); //added these for testing, but still nothing 

     Listener.Prefixes.Add(
      string.Format("http://::ffff:{0}:{1}/", 
      "*", Port)); //added these for testing, but still nothing 

     Listener.Start(); 
     Listener.BeginGetContext(ProcessRequest, Listener); 

     Log.Add(string.Format("HTTP Server started on port {0}", 
      Port), LogType.Info, true); 
    } 

    private void ProcessRequest(IAsyncResult result) 
    { 
     HttpListener listener = (HttpListener)result.AsyncState; 
     HttpListenerContext context = listener.EndGetContext(result); 

     HttpListenerRequest request = context.Request; 
     HttpListenerResponse response = context.Response; 

     string[] UrlParts = request.RawUrl.Split('/'); 
     Response output; 

     if (request.RawUrl == "/index") 
      output = new Response(context.Response.OutputStream, 
       ResponseType.Stats, UrlParts, Log); 

     response.ContentLength64 = output.Size; 
     response.ContentType = output.Header; 

     output.Send(); 

     if (result.IsCompleted) 
      Log.Add(String.Format("OUT > {1,15} {0,8} bytes -> {2}", 
       output.Size, request.RemoteEndPoint.Address, 
       request.RawUrl), LogType.Info, true); 

     Listener.BeginGetContext(ProcessRequest, Listener); 
    } 
} 
+0

आप कुछ कोड प्रदान कर सकता है? आप HttpListener कैसे शुरू कर रहे हैं? –

उत्तर

4

एक तरीका यह त्रुटि तब होती है जब http.sys वैध UrlAcl के की अपनी सूची के साथ HTTP होस्ट शीर्ष लेख से मेल नहीं कर सकते हैं। यह होस्टनाम को हल करने में समस्याओं के कारण हो सकता है।

  1. Related answer explaining configuration steps
  2. MSDN documentation about setting up HTTP stand-alone
  3. Fixing a “Bad Request (Invalid Hostname)” - 400 Error, on Windows IIS Server (प्रासंगिक संभावित समाधानों और टीका)

आप आदेश पंक्ति पर मैपिंग सूचीबद्ध कर सकते हैं:

Windows XP Support Tools/2003 Support Tools - httpcfg

httpcfg query urlacl 

Windows Vista के साथ शामिल/2008/7+ - netsh

netsh http show urlacl