Search code examples
c#.nethttphttplistenerhttplistenerrequest

How can I get form parameters from HttpListenerRequest?


I am using a HttpListener to implement a very simple http server, which is accepting a POST from a Java client. When the client calls I get a HttpListenerRequest, which contains all the form parameters. How can I extract the form parameters? I seem to have access only to the content stream....


Solution

  • HttpListener is a low-level component, as is the HttpListenerRequest object you get for each request. Form data sent via POST is contained within the body, so you will have to process the stream and extract the form data yourself. The QueryString data is available to you because that is part of the request address, and does not require any stream processing to extract. That differentiates it from the form data, as processing the stream IS required.