How to build a valid HTTP Response. Recv failure: Connection reset by peer I'm developing an Arduino server that should respond with a message when it receives a POST Request.

If I test my project with a HTTP Client (like insomnia or postman), I get an error:

Error: Failure when receiving data from the peer


I still get a response that I can read but with a final error.

That's my client request:

&gt; POST /SOMETHING/ HTTP/1.1
&gt; Host: [ARDUINO IP]
&gt; User-Agent: insomnia/6.2.0
&gt; Accept: */*
&gt; Content-Length: 0


And this is my Arduino response considered as not valid:

&lt; HTTP/1.1 200 OK
&lt; Connection: close
&lt; [MY MESSAGE]

* Recv failure: Connection reset by peer
* stopped the pause stream!
* Closing connection 2


As you can notice, I just added 2 strings

HTTP/1.1 200 OK
Connection: close


before the real message.

Am I missing something to create a valid response?

Thanks
HTTP requires an empty line after HTTP headers.

First line is status line. Then the header lines. The headers are terminated by an empty line. Then the response body follows. Line terminator for HTTP is \r\n. Arduino println() function uses \r\n.

The response with body should contain Content-type and Content-length header. Alternative to Content-lenght is "chunked" Transfer-Encoding.

ESP8266WebServer library handles HTTP for you.