1

In Postman,this get request works perfectly fine,and returns expected result,but when requesting in Angular,it keeps throwing this error.

const headerDict = {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
      'Access-Control-Allow-Headers': '*',
      'Control-Allow-Origin':'*',
      "Authorization":"my-auth"

    }
    
    const requestOptions = {                                                                                                                                                                                 
      headers: new HttpHeaders(headerDict), 
    };
    
    this.http.get('https://geo.konkurs2022.digitalcube.dev/api/countries/?fields=id,capital_id,name,capital_name&format=csv&no_paginate=true&order_by=-capital_name',requestOptions)
  • 1
    Are you running from localhost:4200? Could be CORS issue! https://stackoverflow.com/questions/31612931/cors-issue-on-localhost-while-calling-rest-service-from-angularjs – Aakash Goplani Jan 15 '22 at 14:28
  • I'm aware it's CORS issue,but shouldn't it be fixed with 'Access-Control-Allow-Headers': '*' and 'Control-Allow-Origin':'*' ? –  Jan 15 '22 at 14:34

0 Answers0