Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Requests, body vs param vs headers vs data

I am new to HTTP requests (GET, POST, PUT, ETC.) and I am having some issues understanding the "anatomy" of these procedures.

What exactly is the difference between the body and the data? Are they the same thing? Or are headers the same thing as the param? When authentication takes place, are the username and password params or headers or does it vary from API to API? Any help is greatly appreciated. Are there any tutorials or reads you recommend to better understand how to deal with HTTP requests?

Thank you!

like image 704
DCS Avatar asked Jul 19 '18 18:07

DCS


2 Answers

Based on This article and some points of others, you could find out about differences between HTTP header & HTTP parameter ,and and also Body:

Header:

  • meta data about the request
  • HTTP Headers are NOT part of the URL
  • if it's information about the request or about the client, then the header is appropriate
  • headers are hidden to end-users
  • globally data
  • restrict Dos-attack by detecting authorisation on it's header, because a header can be accessed before the body is downloaded

Param:

  • the query params are within the URL
  • like this "tag=networking&order=newest"
  • if it's the content of the request itself, then it's a parameter
  • The product id and requested image size are examples of "some detail" (or parameter) being supplied as part of the content of a request
  • parameters can be seen by end-users (query parameters) on URL

Body:

  • data of business logic
  • important information
  • unlike body, proxy servers are allowed to modify headers
  • data in specefic kinds of requests
  • you can pass token by body as encoding & decoding in servers
like image 184
Mohammad Hossein Ganjyar Avatar answered Nov 06 '22 21:11

Mohammad Hossein Ganjyar


For a full and correct understanding of these questions, RFC2616 recommend by Remy Lebeau is worth reading.

What exactly is the difference between the body and the data?

If you are reading some blog, the body (HTTP body) is be used to transfer data (probably in JSON format). The body carries data, in another way, you get data from body.

Are they the same thing?

So they are not same at all.

Or are headers the same thing as the param?

Header (HTTP header) is related to body, they are part of the HTTP message. As param, it's usually refer to http request param, which usually looks like the following part of the question mark
url?paramName=paramValue&paramTwo=Value2

When authentication takes place, are the username and password params or headers or does it vary from API to API?

They vary for different API's, normally not in param, probably in body of a post request.

Again, start from the RFC2616 would be a good choice.

like image 1
Shihe Zhang Avatar answered Nov 06 '22 21:11

Shihe Zhang