title: .net http webclient to nodejs server. How to access data?
body: <p>I have a .net c# client software that sends data like this:</p>
  
  <pre><code>using(WebClient client = new WebClient())
  {
      string serialisedData = "";
      serialisedData = JsonConvert.SerializeObject(myData);
      client.Credentials = new NetworkCredential(config.UserData.Username, config.UserData.Password);
      byte[] responsebyte = client.UploadData(config.ServerAddress, System.Text.Encoding.UTF8.GetBytes(serialisedData));
  }
  </code></pre>
  
  <p>In nodejs, I currently have this kind of https setup:</p>
  
  <pre><code>_server = https.createServer({
              key: fs.readFileSync(`${__dirname}\\bin\\cert\\${_config.sslkey}`, "utf8"),
              cert: fs.readFileSync(`${__dirname}\\bin\\cert\\${_config.sslcert}`, "utf8")
          }, _listener);
  _server.listen(_config.port, "0.0.0.0");
  
  function _listener(req, res) {
      let data = []
      req.on('data', chunk =&gt; {
          data.push(chunk)
      })
      req.on('end', () =&gt; {
          JSON.parse(data)
      })
  }
  </code></pre>
  
  <p>Now my problem. I cant get any data of the req or res object. Both "on" functionts dont fire and I dont know what to do now. Whats the right way to do this in NodeJS? (c# Code cant be changed)</p>
  
  <hr>
  
  <p>Edit:
  Here is the c# Server Code that works. How can I translate that into nodejs?</p>
  
  <pre><code>HttpListener listener = new HttpListener();
  listener.Prefixes.Add($"https://+:{Config.Port}/");
  listener.AuthenticationSchemes = AuthenticationSchemes.Basic;
  listener.Start();
  for (; ; )
  {
      Console.WriteLine("Listening...");
      IAsyncResult result = listener.BeginGetContext(new AsyncCallback(DoWork), listener);
      result.AsyncWaitHandle.WaitOne();
      result = null;
  }
  
  private void DoWork(IAsyncResult asyncResult)
  {
      HttpListener listener = (HttpListener)asyncResult.AsyncState;
      HttpListenerContext context = listener.EndGetContext(asyncResult);
      HttpListenerRequest request = context.Request;
      HttpListenerResponse response = context.Response;
      HttpListenerBasicIdentity identity = (HttpListenerBasicIdentity)context.User.Identity;
  
  
      string data;
      using (var reader = new StreamReader(request.InputStream, request.ContentEncoding))
      {
          data = reader.ReadToEnd();
      }
      ....
      More Code
      ....
  
      string responseSerial = JsonConvert.SerializeObject(responseData);
      byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseSerial);
      response.ContentLength64 = buffer.Length;
  
      System.IO.Stream output = response.OutputStream;
      output.Write(buffer, 0, buffer.Length);
      output.Close();
  }
  </code></pre>