-1

I am trying (for a small personal project) to send an http (not https as I don't have it set up) to my vps running nodejs. I can send the request perfectly fine with postman, but trying to use the xmlhttprequest prints the following error to the console:

Access to XMLHttpRequest at 'http://207.154.211.105/?postBidone={%22id%22:{%22nome%22:%22esempio1%22,%22localita%22:%22esempio2%22,%22extra%22:%22esempio3%22},%22action%22:%22add%22,%22content%22:%22plastic%22}' from origin 'null' has been blocked by CORS policy: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

Do you know a way to successfully send the request? Thanks!

  • There are thousands of questions about CORS errors here. What research have you done? – Barmar Jun 26 '22 at 06:51
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jun 26 '22 at 06:54
  • Does this answer your question? [Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-receive-a-no-access-control-allow-origin-header-i) – Karl-Johan Sjögren Jun 26 '22 at 06:57

1 Answers1

-1

Please have a look at this post and enable CORS, which will fix this issue. How to enable cors nodejs with express?

If not please provide more code / context.

Erwin van Hoof
  • 957
  • 5
  • 17