salesforce / lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation
https://lwc.dev
Other
1.64k stars 392 forks source link

CORS policy issue while Hit a callout #2076

Closed gowthamjohn closed 4 years ago

gowthamjohn commented 4 years ago

Iam trying to do a callout with GET operation

Added in CORS and Remote site settings

Working in apex class and post man, but not working in Lightning web component

Here is the code

`HttpRequest req = new HttpRequest(); Http http = new Http(); req.setMethod('GET');

String url = 'https://maps.googleapis.com/maps/api/distancematrix/json' / ... /;

req.setEndPoint(url); HTTPResponse resp = http.send(req); system.debug('resp '+resp.getbody());`

image

pmdartus commented 4 years ago

As stated in the error message, the fetch request is blocked due to CORS which is unrelated to the LWC framework. Please refer to the Google Maps API documentation and the different thread on Stack Overflow for more details.

m7mdharoun commented 3 years ago

AIzaSyDEDeoI-XwIyBOyWY0snI8MG_yIIFBcJ7I

Remove this key This Cost you many money!