报错信息

原因是:我在axios中设置了mytoken,但是服务器跨域的代码中没有mytoken,所以加上去就可以了。

<script type="text/javascript">//axios拦截器axios.interceptors.request.use(function(config){console.log(config.url)config.headers.mytoken='nihao'   //就是这里!!!!return config},function(err){console.log(err)})axios.get('http://localhost:3000/axios').then(function(ret){console.log(ret)})</script>
res.header("Access-Control-Allow-Headers",['mytoken'])

这里为什么用数组呢?因为如果有多个请求头名字一样,需要写成数组:

//设置允许跨域访问该网址
app.all('*',function(req,res,next){res.header("Access-Control-Allow-Origin","*")res.header("Access-Control-Allow-Methods",'PUT,GET,POST,DELETE,OPTIONS')res.header("Access-Control-Allow-Headers",['Content-Type','access-token','mytoken'])  //三个的请求头是一样的,所以一起写成数组形式next()
})

这样就解决啦!撒花花!!!

Request header field mytoken is not allowed by Access-Control-Allow-Headers in preflight (请求头设置问题)相关推荐

  1. Request header field Content-Type is not allowed by Access-Control-Allow-Headers跨域

    跨域错误提示: XMLHttpRequest cannot load http://xxx.com. Request header field Content-Type is not allowed ...

  2. 解决:Request header field Content-Type is not allowed by Access-Control-Allow-Headers

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. 前端 vue 工程 post 请求后端接口,报错: Request header field ...

  3. axios.post请求出错:Request header field content-type is not allowed by Access-Control-Allow-Headers in……

    axios.post请求出错:Request header field content-type is not allowed by Access-Control-Allow-Headers in-- ...

  4. Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight respon

    一.问题: 跨域请求中包含自定义header字段时,浏览器console报错. Request header field xfilesize is not allowed by Access-Cont ...

  5. Request header field xxx is not allowed by Access-Control-Allow-Headers in preflight respon

    调试时发现低版本的WebView无法请求跨域接口 请求信息如下: Request Method:OPTIONS Status Code:200 OKAccess-Control-Allow-Heade ...

  6. 解决Request header field XXX is not allowed by access-control-allow-headers in preflight response

    问题 Access to XMLHttpRequest at 'http://B.com/path/a' from origin 'http://A.com' has been blocked by ...

  7. 完美解决nginx跨域问题Request header field x-token is not allowed by Access-Control-Allow-Headers in prefligh

    Access-Control-Allow-Headers 响应首部 Access-Control-Allow-Headers 用于 preflight request (预检请求)中,列出了将会在正式 ...

  8. Request header field token is not allowed by Access-Control-Allow-Headers in preflight response

    之前开发vue项目时,需要在请求头里添加一个token字段,开发的时候都正常,等到部署到正式环境发现很多版本比较低的chorme浏览器都报错,错误如下: XMLHttpRequest cannot l ...

  9. Request header field content-type is not allowed by Access-Control-Allow-Headers(请求头设置问题)

    错误如上图.翻译过来就是:访问控制允许标题不允许使用请求标题字段内容类型.要么是自己设置的请求头信息不对,要么就是重复设置导致覆盖出错. 检查自己在前后台交互的时候设置的请求头的相关信息,不要重复设置 ...

  10. Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight respo

    在axios请求中出现: 问题描述: 如下图展示,在 请求接口的时候,第一个接口返回200,但是第二个接口却返回0. 上图是请求日本的域名,然而请求国内的域名是没有问题的. 下面对比一下日本预检请求截 ...

最新文章

  1. idea类模版,创建时生成一句歌词
  2. mysql生成100000个数据并检验索引的效果
  3. jsp里面的input的值吗_一个jsp页面中的input框向另一个jsp页面的input框传值
  4. ubuntu 下安装 cudnn
  5. Spring5参考指南:容器扩展
  6. ssacanf\Sprintf格式化字符串
  7. php7 memcached sasl,Mac安装memcached扩展支持sasl
  8. android 编程 输入矩阵,Android中Matrix的pre post set方法理解
  9. Swift学习笔记十二
  10. Web 2.0理念在产品应用中的借鉴之处
  11. Python基础-序列化(json/pickle)
  12. QMS-云质-质量管理软件-企业数字化质量管理解决方案
  13. ModifyStyle()调用不起作用
  14. C盘清理攻略--拯救你的C盘空间
  15. “逃离北上广”——你以为回到小城市就很幸福了么?
  16. 学信认证使用Jetbrains教育授权方式
  17. 龙芯电脑开启串口的console控制台配置
  18. http库三剑客:httpx
  19. 百度网盘html资源,百度网盘目录索引搭建教程:如何把百度网盘文件做成在线html目录...
  20. Asciinema终端SSH录屏神器使用

热门文章

  1. 504.七进制数(力扣leetcode) 博主可答疑该问题
  2. 如何提高代码复用性,定义骨架?
  3. nginx 查看当前的连接数
  4. Zookeeper-单机/集群安装
  5. HDU 5879 Cure -2016 ICPC 青岛赛区网络赛
  6. ArcGIS多面体(multipatch)解析——引
  7. 偏向锁、轻量级锁、重量级锁、锁升级、锁对比
  8. SpringApplication#run⽅法的第6步,创建ApplicationContext(五)
  9. SpringApplication run方法第四步解析(三)[(未完结,暂搁置)]
  10. java 开发必备的安全架构知识