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
- 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:
Content-Type: application/x-www-form-urlencoded;charset=utf-8
title=test&sub%5B%5D=1&sub%5B%5D=2&sub%5B%5D=3
- 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
{"title":"test","sub":[1,2,3]}
text/xml
- The message body of the request is an xml fragment.
refer to