I am using the C # HttpListener class to implement some server. And here is the problem. I just want to send the client an empty response to the request, for example
HTTP/1.1 200 OK
or
HTTP/1.1 400 Bad Request
without additional text. Therefore, I set the status code and description of the state and do not write any bytes in the response of OutputStream - I just do not need them. Then close the response to initiate sending bytes to the client using the response.Close () method. And what I get on the client side shown by Fiddler is
HTTP/1.1 200 OK Transfer-Encoding: chunked Server: Microsoft-HTTPAPI/2.0 Date: Sun, 25 Oct 2015 10:42:12 GMT 0
There is a workaround for the "Server" and "Date" fields - HttpListener C # header header .
But how to remove these โTransfer-Encoding: chunkedโ and โ0โ attributes from this answer ?!
Thank you all in advance!
Code:
private void ProcessContext(HttpListenerContext aContext) { HttpListenerResponse response = aContext.Response; response.StatusCode = (int)HttpStatusCode.OK; response.StatusDescription = "OK"; response.Close(); }
Pavel source share