Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response but it can use GET and POST Method [duplicate]

  angular, httpmodule, php, rest

I have some problems with Angular.

I’m using Angular to send the DELETE and PUT method to the RESTful server, it does not work but I can use the GET and POST Method
I’ve already used the header("Access-Control-Allow-Origin: *"); in my RESTful PHP file.

When I send the Delete Method to the RESTful server, it respone the "Access to XMLHttpRequest at ‘http://127.0.0.1/ATWD2/CW/Controller.php/cluster/76’ from origin ‘http://localhost:4200’ has been blocked by CORS policy: Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response."

So, how can I fix this problem?

My Code here vvvv

 this.http.delete('http://127.0.0.1/ATWD2/CW/Controller.php/cluster/'+
    this.data[5]
    ) .subscribe(
      res => {
        console.log(res);
        this.serverData = res;
      },
      res => {
        console.log('error');
      },
      () => {

      }
    )

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.