-1

I want to read a pdf file though the api, but it gives me this error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

this is my cors.php

<?php

return [

    'paths' => ['*'],

    'allowed_methods' => ['*'],

    'allowed_origins' => ['*'],

    'allowed_origins_patterns' => [],

    'allowed_headers' => ['*'],

    'exposed_headers' => false,

    'max_age' => false,

    'supports_credentials' => false,

];

Will Cors help me in this scenario, or does the storage link folder need some other configrations in order for it to work? How can I solve this error?

Amir
  • 473
  • 2
  • 11
  • 24

1 Answers1

0
Reason: CORS header ‘Access-Control-Allow-Origin’ missing

This says most of it. You did not pass the header from the server. If you have access to the API (if you can modify it's code), then send this header from the API before sending any output request.

header('Access-Control-Allow-Origin : *')
// change this for other methods that you allow to be exposed
header('Access-Control-Allow-Methods : GET, POST')
  • it didn't work, I tried adding it in the api function before returning the its data. but it didn't work. is that where I should put it – Amir Jun 24 '20 at 06:58
  • You can try adding it when you receive a request, so when you send the results anytime, this header will already be present in the result. – Durgesh Pandey Jun 24 '20 at 08:01