1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to fix CORS error while accessing cross domain API

Discussão em 'Angular' iniciado por Shiladittya Chakraborty, Setembro 28, 2024 às 08:33.

  1. I am working on Angular project implement login/registration and dashboard API. As a backend I am using spring boot API with spring security. Below is the spring security implementation

    [​IMG]

    Now while calling doLogin and doRegister API from angular then its working fine but while its trying to call dashboard API then its giving CORS errors. Please find below error details

    [​IMG]

    As dashboard API is called after login so we passed token in the header below

    [​IMG]

    To support the cross origin I have tried below approach

    1. Added @CrossOrigin annotation in the controller like below

    [​IMG]

    Using this approach facing CROS error for dashboard API calling.

    Second approach: Added configuration class which only having CROS related details

    [​IMG]

    After adding configuration again tried but still facing same issue.

    Also tried to add below property in the header while calling API from Angular

    'Access-Control-Allow-Origin': 'http://localhost:4200',
    'Access-Control-Allow-Methods': 'GET,POST,OPTIONS,DELETE,PUT',
    'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token'


    But still facing same issue.

    Any help will appreciate.

    Note: Able to call all the API successfully from POSTMAN but not able to call from Angular.

    Continue reading...

Compartilhe esta Página