Detailed difference between GET and POST requests

Preface: As the most common request method, it is likely to be asked in the interview, so here is a brief summary

GET

  • The get method sends parameters to the page request
  • Use ? to separate the address and parameters. For example, localhost:80/download.html?fileName=+"fileName"+"&filePath="+filePath
  • The string will be displayed on the url of the address bar. Insecure sensitive information cannot be used to get (such as login)
  • The get method has a size limit, and the request character can only be up to 1024 bytes
  • get requests will be cached
  • get requests will be saved in the browser log
  • get requests can be bookmarked
  • The encoding type of the get request is application/x-www-from-urlencoded
  • Only ASCII data types are allowed, binary streams are not allowed (upload can't use get)
  • Click to refresh, the get request data remains unchanged and the page will not change
  • The get request is mainly used to obtain data

POST

  • The post method wants to send a page with parameters
  • When using the post method, the query string exists alone in the post information and is sent to the server along with HTTP
  • The encoding type is application/x-www-form-urlencoded and the binary is multipart
  • no history
  • The parameter type is not limited, it can be a string or a binary stream
  • The data will not be displayed in the address bar, nor will it be cached or stored in the browsing history, so post is safer than get, but it is not the safest way. For example, when transmitting sensitive data, it must be encrypted.
  • The amount of data transmitted by post can reach 2M, while get can only be 1024 bytes due to the limitation of url length

in general

POST is suitable for transferring data to the server

GET is suitable for getting data from the server side

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325368555&siteId=291194637