HTTP request method 面试题

2017-09-27  本文已影响30人  Zihowe

GET

It requests a resource at the request URL. It should not contain a request body as it will be discarded. May be it can be cached locally or on the server.

get的参数在哪?

get的query string 或者说name/value pairs 存在于url中
/test/demo_form.php?name1=value1&name2=value2


POST 创建数据 post,是unsafe的,多次post,服务器可能会创建多个resource

post的参数在哪?

post的query string 或者说name/value pairs 存在于http message body

POST /test/demo_form.php  HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
<method> <request-URL> <version>
<headers>
<entity-body>

所以再问post body在哪,可以回答在header的后面~

extra bonus

application/json
POST http://www.example.com HTTP/1.1
Content-Type: application/json;charset=utf-8
{"title":"test","sub":[1,2,3]}

上面这个json 也是在header后面,这个header里面包含了content-type信息和charset编码信息

上一篇 下一篇

猜你喜欢

热点阅读