請求相關

請求頭中Content-Type傳參 application/json與application/x-www-form-urlencoded

若是是application/json ,通常用於post請求,傳輸給後臺數據格式必須是「對象」或/jsonjavascript

fetch(url,{
            method:"post",
            mode: 'cors',
            headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        body:JSON.stringify({test:'test'})
})
複製代碼

若是是application/x-www-form-urlencoded 通常用戶get,或post請求,傳輸給後臺數據格式爲默認編碼格式java

fetch(url,{
            method:"post",
            mode: 'cors',
            headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        body:"name=test&test=test"
})
複製代碼
相關文章
相關標籤/搜索