Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Axios对PHP API的GET请求不使用自定义头_Php_Vue.js_Vuejs2_Axios_Cors - Fatal编程技术网

Axios对PHP API的GET请求不使用自定义头

Axios对PHP API的GET请求不使用自定义头,php,vue.js,vuejs2,axios,cors,Php,Vue.js,Vuejs2,Axios,Cors,我正在开发一个新的VueJS应用程序,它通过axios访问PHP中构建的简单API端点。我已将PHP端点代码剥离为一个简单的回显,以排除导致问题的其他代码: 我认为在这一部分: axios.interceptors.request.use(function (config) { config.headers = { 'X-Api-Token': 'test' }; return config; }); 您正在覆盖请求的所有标头。尝试将标题添加到标题中,而

我正在开发一个新的VueJS应用程序,它通过axios访问PHP中构建的简单API端点。我已将PHP端点代码剥离为一个简单的回显,以排除导致问题的其他代码:


我认为在这一部分:

axios.interceptors.request.use(function (config) {
    config.headers = {
        'X-Api-Token': 'test'
    };
    return config;
});
您正在覆盖请求的所有标头。尝试将标题添加到标题中,而不是覆盖它们,例如:

axios.interceptors.request.use(function (config) {
    config.headers.token = "test";
    return config;
});

我试过了,但也没用。我还确保在backbend上反映“token”名称,仍然是同一个问题。我发现“simple requests”不允许自定义头…这很奇怪,因为我可以使用jQuery的Ajax()发送自定义头。