概述:
x-www-form-urlencoded
紙面翻譯即所謂url格式的編碼,是post的默認Content-Type,其實我覺得可以認爲get和post的默認表單數據傳遞格式都一樣,只是一個在url地址後面加 ?再加表單數據,另一個是把表單數據寫在請求體內
一、位置:
- 請求頭內的
Content-Type
字段裏,
二、寫法:
Content-Type:application/x-www-form-urlencoded
三、用處:
- get請求的請求體格式是什麼?get請求是拼接在url後面請求的,一般如此
username=tom&pwd=123
,這樣的格式叫查詢參數,x-www-form-urlencoded
也長這樣,只是不添加到url後面; - 要知道post的默認數據傳輸格式就是
x-www-form-urlencoded
,所以爲什麼在post數據的時候需要把數據轉爲url格式(username=tom&pwd=123
),一般使用qs
庫的qs.stringify()
方法就能把json對象轉換成url格式編碼(x-www-form-urlencoded
)