My goal is to send a username and password to my backend server. However, I am encountering an issue where the data does not successfully reach the backend when using the following code:
function register() {
var text = '{"username":"admin1","password":"1234"}';
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:8087/meetmeserver/api/admin/register", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify(text));
}
Interestingly, if I omit the line containing xhr.setRequestHeader
, the data reaches the backend but triggers an exception...
I am stuck at this point and would greatly appreciate any assistance in identifying the problem. Please let me know if you require additional code samples.