title: HttpListener returns bad request 400
body: <p>I have the next problem. I have a windows service written in c# using HttpListener. The code of my server class:</p>
  
  <pre><code>public class SoaphttpServer
      {
          private HttpListener _listener;
          private readonly IniFile _settings;
  
          public bool Terminated { get; private set; }
  
          public void Terminate()
          {
              Terminated = true;
              Common.Cts.Cancel();
          }
  
          public SoaphttpServer()
          {
              _settings = Common.ReadSettings();
              Terminated = false;
              ServicePointManager.DefaultConnectionLimit = 500;
              ServicePointManager.Expect100Continue = false;
              ServicePointManager.MaxServicePoints = 500;
          }
  
          public void StartServer()
          {
              try
              {
                  Common.Cts = new CancellationTokenSource();
                  _listener = new HttpListener();
                  _listener.Prefixes.Add("http://*:8012/");
                  _listener.Start();
                  while (!Terminated)
                  {
                      IAsyncResult result = _listener.BeginGetContext(ListenerCallback, _listener);
                      while (!result.AsyncWaitHandle.WaitOne(1000))
                      {
                          if (Terminated) break;
                      }
                  }
              }
              catch (Exception ex)
              {
                  Log.Write("StartServer: " + ex.Message);
              }
          }
  
          public static async void ListenerCallback(IAsyncResult result)
          {
              Log.Write("new connection");
              HttpListener listener = (HttpListener)result.AsyncState;
              HttpListenerContext context = listener.EndGetContext(result);
  
              SoapHttpClient client = new SoapHttpClient(context);
              await client.SomeFuncAsync();
          }
  
          ~SoaphttpServer()
          {
              if (_listener == null) return;
              _listener.Stop();
              _listener.Close();
          }
  
      }
  </code></pre>
  
  <p>In command line i executed next command:</p>
  
  <pre><code>netsh http add urlacl url="http://*:8012/" user="NETWORK SERVICE"
  </code></pre>
  
  <p>Everything works well from all places. I can accept connection from broweser, or from delphi programm using IdHTTP. But when i'm trying to connect from one programm (i have no code from this program), written in delphi to my service i'm getting in this programm: "HTTP/1.1 400 Bad Request". Previous version of this programm worked well with my service. I know that there were no changes in communication protocol in this programm. I found out using Wireshark that GET packet comes to my computer, but, as i think HttpListener forming this response (bad request) and sending back it without me. What can be the problem? Maybe i can ovverride some methods of HttpListener and look at incoming request from this prog and find out what is wrong where?</p>
  
  <p>Upd. I have found out that HttpListener is sealed class. How can i find a trouble place?</p>