zoukankan      html  css  js  c++  java
  • 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,好像

    问题已解决

  • 相关阅读:
    JavaScript对象继承的实现
    Redis资料
    Difference between LINQ to SQL and the Entity Framework
    闭包,懂不懂由你,反正我是懂了
    Castle资料
    csu 1242 碱基配对
    csu 1242 碱基配对——一个错误的解答
    [转载]zoj 分类
    计算素数
    魔方阵
  • 原文地址:https://www.cnblogs.com/hhweb/p/7885538.html
Copyright © 2011-2022 走看看