Hypertext Transfer Protocol is an application-layer protocol for transferring data over the network, which is the core of the WWW (World Wide Web) and provides communication between HTTP clients (browser or mobile application) and servers. HTTP is built around messages called request and response. The client sends a request to the server, then the server processes this request and sends a response back to the client. Any HTTP message consists of a request/response line, HTTP headers, and a message body.
What is a POST request?
The HTTP POST method requests the webserver to receive and process the data enclosed in the body of the POST message. The POST is one of the nine standard HTTP methods. The POST method is used to send data to the server, upload files and images, as well as for and send HTML forms. POST requests differ from GET and HEAD requests in that they can change the state of the server.
What does the Content-Length header mean?
A Content-Length header is a number that indicates the size of the data in the body of the request or response in bytes. The HTTP body begins immediately after the first blank line, after the initial line and headers. The actual length of the content sent over the network may differ from the size of the data in the body because servers can compress the data before sending it.
length: the length of the message body is specified in bytes.
How to add a Content-Length header to the POST request?
Clients (browsers, mobile apps) automatically add a Content-Length header to the POST request based on the size of your data in the request. In this example, the Content-Length header indicates the size of the provided JSON.