1

I am having CORS issue with PHP. I have following code in my angular:

 $http({
        url: url,
        method: "GET",
        headers: {
            'Authorization': 'Bearer zPwDlSp5AKv7MnZRwWyULhavD3WmTFPH',
            'Content-Type': 'application/json'
        },
        data: JSON.stringify({'user_id': '17'})
    }).then(function(response) {
        console.log('Success!');
        console.log(response.data);
    }, function(response) {
        console.log('Failed!');
        console.log(response);
    })

And following php code in backend:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Authorization, X-Requested-With, Content-Type, Accept, Origin");
header('Access-Control-Allow-Credentials: true');

However, headers are set correctly I got:-

preflight request error.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Umid Boltabaev
  • 442
  • 2
  • 6
  • 17

0 Answers0