• preflight response 应该是异步的什么问题---后来发现不是,是axios参数格式问题,网上其他一些解答太误导人了


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

    用的axios做的请求,express后端返回,post请求时报这个错

    设置Axios.post('/api-user/login/login', params, {headers: {'sign': sign}}); 后面的sign时报

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

    原因?求解

    ----------------------------------------------------------

    let params={name:'hhl',psd:'123456'};
    let out=Axios.get('/login',{params:params});  //格式不这么写就报 in preflight response

    let out2=Axios.post('/login/abort', qs.stringify(params) ); //post需要用qs来转化一下

    axios没有配置什么,express配置跨域

    app.all('*', function(req, res, next) {
      res.header("Access-Control-Allow-Origin", "*");
      res.header("Access-Control-Allow-Headers", "X-Requested-With");
      res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
      res.header("X-Powered-By",' 3.2.1');
      res.header("Content-Type", "application/json;charset=utf-8");
      next();

    }

    其中主要是origin,好像

    问题已解决

  • 相关阅读:
    Cesium加载倾斜摄影数据
    CentOS7安装Docker
    Docker镜像下载
    c#验证密码强度
    配置阿里yum源
    ftpbat脚本
    powershell-ftpmove文件到本地
    Session Setup Request,NTLMSSP_AUTH, User:Dmainhostname$
    smblog
    树莓派显示器屏幕休眠
  • 原文地址:https://www.cnblogs.com/hhweb/p/7885538.html
Copyright © 2020-2023  润新知