OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Getting CORS error while calling API from Angular 16 to Laravel 10

  • Thread starter Thread starter Ejaaz Khan
  • Start date Start date
E

Ejaaz Khan

Guest
Getting below error while calling API from Angular to Laravel

Access to XMLHttpRequest at 'http://localhost:8000/api/v1/authenticate' from origin 'http://localhost:4201' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I already tried adding headers in Angular for CORS but nothing worked for me. I have checked Laravel 10 cors file every thing is good from there and I also added below code in boostrap/app.php

Code:
header("Access-Control-Allow-Headers: Origin, userKey, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 3600");
header('content-type: application/json; charset=utf-8');

<p>Getting below error while calling API from Angular to Laravel</p>
<blockquote>
<p>Access to XMLHttpRequest at 'http://localhost:8000/api/v1/authenticate' from origin 'http://localhost:4201' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.</p>
</blockquote>
<p>I already tried adding headers in Angular for CORS but nothing worked for me.
I have checked Laravel 10 cors file every thing is good from there and I also added below code in boostrap/app.php</p>
<pre class="lang-php prettyprint-override"><code>header("Access-Control-Allow-Headers: Origin, userKey, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Access-Control-Allow-Headers, Authorization, observe, enctype, Content-Length, X-Csrf-Token");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 3600");
header('content-type: application/json; charset=utf-8');
</code></pre>
 

Latest posts

Top