I try to access a remote REST API service using QML. According to the service API I have to use HTTPS requests. I don't know how to interpret the output I get from the code.
methods.js
function makeRequest()
{
var doc = new XMLHttpRequest();
doc.onreadystatechange = function() {
if (doc.readyState == XMLHttpRequest.HEADERS_RECEIVED) {
console.debug("Headers -->");
console.debug(doc.getAllResponseHeaders ());
console.debug("Last modified -->");
console.debug(doc.getResponseHeader ("Last-Modified"));
console.debug("error: " + doc.status);
}
}
doc.open("GET", "https://somedomain.com");
//var user="username"
//var pass="password"
doc.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
//doc.setRequestHeader( 'Authorization', 'Basic ' + Qt.btoa( user + ':' + pass ) )
//doc.withCredentials = true;
doc.send();
}
output:
Headers -->
date: Sun, 20 Dec 2020 16:04:25 GMT
server: Apache
cache-control: private
expires: Thu, 01 Jan 1970 01:00:00 CET
www-authenticate: FORM comment="Use form to authenticate"
content-length: 6529
x-powered-by: PleskLin
connection: close
content-type: text/html;charset=ISO-8859-1
Last modified -->
error: 401
commenting out the commented lines doesn't change the output. Does the output try to tell me, that I can only get authentication if I fill the login form? I don't find this very logic, because the service's api is made for automatic interaction with devices.