POST - https://demo.traccar.org/api/session with BasicAuth NullPointerException

thron2629 months ago

Hello everyone,
I have a problem and I don't understand it!

When I do a with Postman a
POST https://demo.traccar.org/api/session with BasicAuth and set the Content-Type application/x-www-form-urlencoded field in the header, I get a NullPointerException as a response! where is my mistake?

I've already compared the values ​​with the web app in the developer tools and I can't find anything wrong.

jean jose de matos9 months ago
// WARNING: For POST requests, body is set to null by browsers.
var data = "email=suporte@domain.com.br&password=pass";

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://domain.com.br/api/session");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");


xhr.send(data);