CORS Failed to Send and Receive post Asynchronous Requests under nodejs

  node.js, question

To send and receive asynchronous requests with cors, I do this:

Let’s create fake data first and try it out:

var mydata = {
 id:timestamp,
 pass:"14444",
 title:"24444",
 tag:"34444",
 content:"544444"
 };
 var XHR = new XMLHttpRequest();
 XHR.open("POST", "http://localhost:8090/savemycollec");
 XHR.setRequestHeader('Content-Type', 'application/json');
 XHR.onreadystatechange = handler;
 XHR.send(JSON.stringify(mydata));

Server:

res.header('Access-Control-Allow-Origin', '*');
 res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept');
 res.header('Access-Control-Allow-Methods', 'POST,GET,DELETE,PUT');
 console.log(req.body);
 console.log(req.query);
 res.end();

The detection value,

The results showed that:

It is still a mistake to report:

XMLHttpRequest cannot load http://localhost:8090/  savemycollec. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested reso  urce. Origin 'http://localhost:63342' is therefore not allowed access.

It seems that the request in json format cannot be directly accepted?

If setRequestHeader is removed from the request, no error will be reported but a null value will be passed (no data will be received)

Please refer to relevant experienced persons for advice.

res.set('Access-Control-Allow-Headers', 'Content-Type');
res.set('Access-Control-Allow-Methods', 'GET, POST, DELETE, PUT');