2
votes

I am working on angular fronted project and using angular7 project. I am using aws api as backend. Whenever I call the aws api its giving me following errors.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://xxxxxxx.execute-api.us-east-1.amazonaws.com/XXX/subscriptionpayment. (Reason: missing token ‘access-control-allow-origin’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://xxxxxxx.execute-api.us-east-1.amazonaws.com/XXX/subscriptionpayment. (Reason: CORS request did not succeed).

I am using following code

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json',
    'Access-Control-Allow-Origin':'*'
  })
};

     let makePaymentUrl = "https://xxxxx.execute-api.us-east-1.amazonaws.com/xxxx/subscriptionpayment";
return this.http.post(makePaymentUrl, params,httpOptions);
2

2 Answers

0
votes

Where are you calling this request? if its a localhost maybe aws doesnt allow access to it. Check your API keys for this services

or double check your headers try this