nodejs怎么处理非简单的cors时预请求的头处理。以下是我的代码但是不通过。
node代码:
var http = require('http'); var server = http.createServer(function(req, res) { res.writeHeader(200,{ 'content-type':'application/json', 'Access-Control-Allow-Origin' : '*', 'Access-Control-Request-Method':'POST,GET,OPTIONS', 'Access-Control-Request-Headers':'content-type'}); res.on('data',function(d){ console.log(d); }) var a={ 'name':'test' }; console.log(a); res.write(JSON.stringify(a)); res.end(); }).listen('8080');
前端代码:

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我用google查到了正确的头设置,希望可以帮助你。(注意allow-headers需要使用加上‘accept’).最更本的是我原本的头设置是错误的。不是access-control-request-headers.应该是access-control-allow-headers
如果自定义header
浏览器会携带options请求
注意加这个
token就是我自定义的header