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
Forum Updated to NodeBB v4.3 + New Features

getResponseHeader doesn't return all fields

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 2.9k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    niqt
    wrote on 22 Jan 2018, 08:36 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.

    R 1 Reply Last reply 23 Jan 2018, 08:25
    0
    • N niqt
      22 Jan 2018, 08:36

      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.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 23 Jan 2018, 08:25 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
      • N Offline
        N Offline
        niqt
        wrote on 26 Jan 2018, 13:04 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.

        R 1 Reply Last reply 26 Jan 2018, 13:30
        0
        • N niqt
          26 Jan 2018, 13:04

          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.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 26 Jan 2018, 13:30 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
          • N Offline
            N Offline
            niqt
            wrote on 12 Feb 2018, 10:12 last edited by
            #5

            Can be a problem https?

            R 1 Reply Last reply 12 Feb 2018, 10:20
            0
            • N niqt
              12 Feb 2018, 10:12

              Can be a problem https?

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 12 Feb 2018, 10:20 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
              • N Offline
                N Offline
                niqt
                wrote on 7 Mar 2018, 14:16 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