Access to XMLHttpRequest has been blocked by CORS policy

后端 未结 7 1737
-上瘾入骨i
-上瘾入骨i 2021-02-18 16:58

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:08

    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);
         });
     });
    }
    

提交回复
热议问题