Access to XMLHttpRequest has been blocked by CORS policy

后端 未结 7 2227
庸人自扰
庸人自扰 2021-02-18 16:49

I\'ve a problem when I try to do PATCH request in an angular 7 web application. In my backend I have:

app.use((re         


        
7条回答
  •  天涯浪人
    2021-02-18 17:06

    use this in Node

        app.use(function (req, res, next) {
        //Enabling CORS
        res.header("Access-Control-Allow-Origin", "*");
        res.header("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
        res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, 
        Accept, x-client-key, x-client-token, x-client-secret, Authorization");
          next();
        });
    

    And in angular the request is

     auth(login): Promise {
     return new Promise((resolve, reject) => {
       this._http.post('url:3000/api/auth/login', { ...login })
         .subscribe((response: any) => {
           resolve(response);
         });
     });
    }
    

提交回复
热议问题