Upon reading stuffs about POST and get methods here there is a statement like " when used post method it uses HTTP request Body . What Does it mean " HTTP request body".?
相关问题
- Views base64 encoded blob in HTML with PHP
- Angular RxJS mergeMap types
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
HTTP Body Data is the data bytes transmitted in an HTTP transaction message immediately following the headers if there is any (in the case of HTTP/0.9 no headers are transmitted).
Most HTTP requests are GET requests without bodies. However, simulating requests with bodies is important to properly stress the proxy code and to test various hooks working with such requests. Most HTTP requests with bodies use POST or PUT request method.
Message Body
The message body part is optional for an HTTP message but if it is available then it is used to carry the entity-body associated with the request or response. If entity body is associated then usually Content-Type and Content-Length headers lines specify the nature of the body associated.
A message body is the one which carries actual HTTP request data (including form data and uploaded etc.) and HTTP response data from the server ( including files, images etc). Following is a simple content of a message body:
For more details to HTTP messages and bodies refer to w3org link
A common use case is an API that expects data in JSON format. Below is an example code snippet taken from Postman, where the API is an Azure Function and the request body is JSON:
The following html
<form>
:will send this HTTP request (which is a type of HTTP message):
Lines
POST / HTTP/1.1
toContent-Length: 465
are the HTTP headers, whilst the rest -- following the empty line -- corresponds to the HTTP message body (also known as content).So how do you access this data in the back-end/server-side?
Different server-languages (e.g. Go-lang, Node.js and PHP... etc) have different ways to parse the
http body
from ahttp post request
. In Node.js it is common to use body-parser which is a parsing middleware function (see example below).More information about bodies:
Bodies can be broadly divided into two categories:
Sources: