Window exe API cors issue when calling from any webapp. C++

  ajax, c++, cors, javascript

We’ve created one EXE file using the CPP language and create one API like http://localhost:5800/get-id/. when I open in browser return me the perfect output.

When I used fetch in HTML > script page, then getting No "Access-Control-Allow-Origin" header is present on the requested resource.

Code1:

fetch("http://localhost:5800/get-id/", {method: 'GET').then(function(response) {
  console.log(response.text()); 
}).catch(function(error) {  
  console.log('Request failed', error)  
});

After research, I’ve added the mode: no-cors error lost but getting an empty response.
Code2:

fetch("http://localhost:5800/get-id/", {method: 'GET', mode: 'no-cors'}).then(function(response) {
  console.log(response.text()); 
}).catch(function(error) {  
  console.log('Request failed', error)  
});

If I use code2 in any inspect console then getting an empty body but when I open http://localhost:5800/get-id/ in the browser and try to hit code2 in the console then getting the perfect parameter.

It means, localhost domain it’s working fine but when it’s fetched from any domain through my error.

What is the proper solution for it? In C/CPP language how can we allow cors?

Strange:

when I hit from console, it’s show me empty
enter image description here

For same request I checked network tab, show 200 OK with proper response / preview data
enter image description here

Source: Windows Questions C++

LEAVE A COMMENT