http请求中,不同请求方式 不同Content-Type,参数传递方式会不一样。
- Query String Parameters
- Form Data
- Request Payload
GET请求
GET请求时,参数会以url string 的形式进行传递,即?后的字符串则为其请求参数,并以&作为分隔符。
Request URL: http://****.com?id26
Request Method: GET
post请求
post请求有两种请求体。
1.FormData
application/x-www-form-urlencoded Request Payload
当发起一次post请求,若未规定content-type,则默认 content-type 为 application/x-www-form-urlencoded,参数会以Form Data传递,并且不会显示在url中。
2.Request Payload
同理当发起一次post请求,若规定content-type为application/json。参数会以Request Payload json串的形式进行参数传递,并且不会显示在url中。
碎碎念
在使用ajax请求,设置content-type为application/json时,会发送两次请求,第一次会先发送method为options的请求到服务器,第一个请求会询问服务器支不支持跨域,如果支持会发送第二次请求,否则报错,不会发送第二次请求。