请求相关

221 阅读1分钟

请求头中Content-Type传参 application/json与application/x-www-form-urlencoded

如果是application/json ,一般用于post请求,传输给后台数据格式必须是“对象”或/json

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请求,传输给后台数据格式为默认编码格式

    fetch(url,{
            method:"post",
            mode: 'cors',
            headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        body:"name=test&test=test"
})