4 common types of submitted data for POST

Introduction to post

  • Comparison of post and get .
  • The encoding method of the message body is specified in the Content-Type request header.
  • The message body contains the request data.

Common Content-Type request headers

application/x-www-form-urlencoded

  • The most common way to submit data is POST, the browser's default submission method.
  • Submitted data is key-value pairs separated by & and transcoded.
POST http://www.example.com HTTP/1.1<br>
Content-Type: application/x-www-form-urlencoded;charset=utf-8

title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3

multipart/form-data

  • Generally used to upload files.
  • Use boundary to separate the content of each field (boundary is longer to avoid conflict with submitted data).
POST http://www.example.com HTTP/1.1
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryrGKCBY7qhFd3TrwA

------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="text"

title
------WebKitFormBoundaryrGKCBY7qhFd3TrwA
Content-Disposition: form-data; name="file"; filename="chrome.png"
Content-Type: image/png

PNG ... content of chrome.png ...
------WebKitFormBoundaryrGKCBY7qhFd3TrwA--

application/json

  • The message body of the request is a json string.
POST http://www.example.com HTTP/1.1 
Content-Type: application/json;charset=utf-8

{"title":"test","sub":[1,2,3]}

text/xml

  • The message body of the request is an xml fragment.

refer to

Guess you like

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