axios跨域Access to XMLHttpRequest

后台设置:
header("Access-Control-Allow-Origin: *");

不起作用.

axios设置请求头headers.

'Content-Type' : 'multipart/form-data'
'Content-Type' : 'application/x-www-form-urlencoded'
const url = "http://www.xxx.com";
const data ={
  name: "Jake Taper",
  email: "taperjake@gmail.com"
};
const config = {
  headers:{
    'Content-Type' : 'multipart/form-data'
  }
};
axios.post(url, data, config)
  .then(res => console.log(res))
  .catch(err => console.log(err))

       axios({
                url: 'http://www.abc.com',
                method: 'POST',
                params: {
                    XXXX: 'XXXXXX'
                },
                headers:{
              'Content-Type' : 'multipart/form-data',
           },
                data: {
                    name: 'zhangsan',
                }
            }).then((res) => {
                console.log('数据:', res);
            })

 

posted @ 2022-09-28 17:08  变形金刚之猩猩将军  阅读(375)  评论(0)    收藏  举报