• Héron Silva
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello guys,

I am currently working on the development of a Lightning Web Components, first time developing for Salesforce. I've already searched everywhere but I couldn't find a working solution in order to make requests to my company's server.

I've already added our server to the list of security trusted sites and I am having problems running the following:
fetch('https://example.com', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    data: { ... }
}).then(function(res) {
    console.log(res);
}).catch(e => console.log(e));
This is the error I get:
Access to fetch at 'https://example.com' from origin 'https://origin-dev-ed.lightning.force.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Our API is returning the required 'Access-Control-Allow-Origin' header and we shouldn't be seeing such error. Or am I missing something?
Hello guys,

I am currently working on the development of a Lightning Web Components, first time developing for Salesforce. I've already searched everywhere but I couldn't find a working solution in order to make requests to my company's server.

I've already added our server to the list of security trusted sites and I am having problems running the following:
fetch('https://example.com', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    data: { ... }
}).then(function(res) {
    console.log(res);
}).catch(e => console.log(e));
This is the error I get:
Access to fetch at 'https://example.com' from origin 'https://origin-dev-ed.lightning.force.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Our API is returning the required 'Access-Control-Allow-Origin' header and we shouldn't be seeing such error. Or am I missing something?
Hello guys,

I am currently working on the development of a Lightning Web Components, first time developing for Salesforce. I've already searched everywhere but I couldn't find a working solution in order to make requests to my company's server.

I've already added our server to the list of security trusted sites and I am having problems running the following:
fetch('https://example.com', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    data: { ... }
}).then(function(res) {
    console.log(res);
}).catch(e => console.log(e));
This is the error I get:
Access to fetch at 'https://example.com' from origin 'https://origin-dev-ed.lightning.force.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Our API is returning the required 'Access-Control-Allow-Origin' header and we shouldn't be seeing such error. Or am I missing something?