Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. getResponseHeader doesn't return all fields
QtWS25 Last Chance

getResponseHeader doesn't return all fields

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • niqtN Offline
    niqtN Offline
    niqt
    wrote on last edited by
    #1

    Hi,
    i'm using var xhr = new XMLHttpRequest(); to do a post request, when i read the response header i don't find all the fields (i.e. Autohorization). Using the c++ classes i can read all the fields. What's the problem with js function?
    N.

    raven-worxR 1 Reply Last reply
    0
    • niqtN niqt

      Hi,
      i'm using var xhr = new XMLHttpRequest(); to do a post request, when i read the response header i don't find all the fields (i.e. Autohorization). Using the c++ classes i can read all the fields. What's the problem with js function?
      N.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @niqt
      you need to be more specific.

      i assume you are using QML / QQmlEngine? Or do you use QtScript?
      Whats the url you are posting to? A custom web server/service?
      Show some code please, maybe you are reading the response too early.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • niqtN Offline
        niqtN Offline
        niqt
        wrote on last edited by
        #3

        My code it's in js file and i call it from qml

        function requestRestUser(verb, endpoint, obj, cb) {
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function() {
        
                if(xhr.readyState === XMLHttpRequest.DONE) {
                    if(cb) {
                        if (xhr.status == "200") {
                            console.log("header" + xhr.getAllResponseHeaders());
                            cb(true, xhr.getResponseHeader('Authorization'));
                        } else if (xhr.status == "400" || xhr.status == "401") {
                            cb(false, "");
                        }
                    }
                }
            }
            xhr.open(verb, endpoint);
            xhr.setRequestHeader('Content-Type', 'application/json');
            var data = (obj)?JSON.stringify(obj):''
            xhr.send(data)
        }
        

        I have 200 code, but the xhr.getResponseHeader('Authorization') is empty (if i do the same with c++ i got it). The remote server ia java rest server.

        raven-worxR 1 Reply Last reply
        0
        • niqtN niqt

          My code it's in js file and i call it from qml

          function requestRestUser(verb, endpoint, obj, cb) {
              var xhr = new XMLHttpRequest();
              xhr.onreadystatechange = function() {
          
                  if(xhr.readyState === XMLHttpRequest.DONE) {
                      if(cb) {
                          if (xhr.status == "200") {
                              console.log("header" + xhr.getAllResponseHeaders());
                              cb(true, xhr.getResponseHeader('Authorization'));
                          } else if (xhr.status == "400" || xhr.status == "401") {
                              cb(false, "");
                          }
                      }
                  }
              }
              xhr.open(verb, endpoint);
              xhr.setRequestHeader('Content-Type', 'application/json');
              var data = (obj)?JSON.stringify(obj):''
              xhr.send(data)
          }
          

          I have 200 code, but the xhr.getResponseHeader('Authorization') is empty (if i do the same with c++ i got it). The remote server ia java rest server.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @niqt
          even though QML's XMLHttpRequest object doesn't enforce the same origin policy, it may be still related to such or similar.
          In case i am right and it's a CORS related issue you might want to try to add the following:

          xhr.setRequestHeader('Access-Control-Expose-Headers', 'Authorization');
          

          Can you sniff the HTTP requests and corresponding responses done with XMLHttpRequest and also with QNetworkAccessManager and post them here? For sniffing you can use a tool like Wireshark for example.

          Maybe your Java webservice doesn't like something about the request sent via XMLHttpRequest. But this should be clearly seen when comparing the Request- and Response-Headers.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • niqtN Offline
            niqtN Offline
            niqt
            wrote on last edited by
            #5

            Can be a problem https?

            raven-worxR 1 Reply Last reply
            0
            • niqtN niqt

              Can be a problem https?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @niqt said in getResponseHeader doesn't return all fields:

              Can be a problem https?

              shouldn't be, since the data after all should be the same.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • niqtN Offline
                niqtN Offline
                niqt
                wrote on last edited by
                #7

                From today it's ok and i don't know why.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved