【问题标题】:Axios is not placing the origin header in the requestAxios 没有在请求中放置源头
【发布时间】:2019-11-28 17:01:51
【问题描述】:

我在 react 中使用 axios,他没有将 Origin 标头放在请求中,所以他给了服务器端 cors (nodejs) 问题。

import axios from 'axios';

const api = axios.create({baseURL: window.location.protocol + '//' + window.location.hostname + '/node/api/', withCredentials: true});

export default api;

查看:https://i.stack.imgur.com/RTwh5.png

【问题讨论】:

    标签: node.js reactjs npm axios


    【解决方案1】:

    我希望这会有所帮助。

    import axios from 'axios';
    axios.defaults.withCredentials = true; 
    const api = axios.create({baseURL: window.location.protocol + '//' + window.location.hostname + '/node/api/'});
    
    export default api;
    

    【讨论】:

    • property assignment expected.ts(1136)
    • 我放了,仍然没有发送标题“Origin”
    • @Henrique withCredentials 即将发送 cookie。如果要添加任何标头,则需要添加 axios.create({baseURL: window.location.protocol + '//' + window.location.hostname + '/node/api/'}, {"headerxxxx":"标头值xxxx"});
    • “Origin”标头不能按月发送,它必须由浏览器自动发送,但这不会发生。用 ajax 发送,已经用 axios 没有了。
    • 为什么要发送 Origin 标头?
    猜你喜欢
    • 2018-07-23
    • 2021-09-25
    • 2020-04-19
    • 1970-01-01
    • 2019-01-04
    • 1970-01-01
    • 2019-10-13
    • 2021-09-06
    • 2019-02-11
    相关资源
    最近更新 更多