Important: Please read the Qt Code of Conduct -


  • I am new to javascript and qml, I am currently working on a task I found online. Here is the javascript function.

    function request() {
            var base = ""
            var access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJjMmJmYmVkZGJiMDg3NTI
            var xhr = new XMLHttpRequest();
  "GET", base);
            xhr.setRequestHeader("authorization","Bearer <<access_token>>")
            xhr.onreadystatechange = function() {
                if (xhr.readyState === XMLHttpRequest.HEADERS_RECEIVED) {
                } else if(xhr.readyState === XMLHttpRequest.DONE) {
                    var json = JSON.parse(xhr.responseText.toString())
                    for(var i = 0; i<json.results.length;i++){
                        movieModel.append({"imageUrl": base + json.results[i].poster_path,"name":json.
                        results[i].original_title,"date": json.results[i].release_date,"stars":json.results[i].vote_average})
    Everything works fine , except for the imageUrl where I am getting the error 

    QML Image: Host requires authentication

    From what i could find, the error might be due to the fact that im using the base url in constructing the url of the image. I should use the url of that point in the website. Can someone help me out please?

  • I don't see anythin in your code that makes this a Qt or QML issue, but to be fair, I don't know QML. It seems to me to be a pure javascript debugging issue.

  • Lifetime Qt Champion

    @Abdulmueez said in Javascript:

    I am getting the error

    What error?

    "xhr.setRequestHeader("authorization","Bearer <<access_token>>")" - I'm really not an JavaScript expert, but shouldn't you put the content of access_token into the second string? Because now second parameter is just "Bearer <<access_token>>" string, it does not contain the actual token.

  • @Kent-Dorfman Yes, it was a javascript issue, already fixed it, the url for the image is different. Thanks a lot

  • Lifetime Qt Champion

    @Abdulmueez So please mark this topic as SOLVED then. Thanks!

  • How do I go about that please

  • Lifetime Qt Champion


    Click on the "Topic Tools" button and you'll have the option.

Log in to reply