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. Trouble Logging into Web API with QNetworkAccessManager
Forum Updated to NodeBB v4.3 + New Features

Trouble Logging into Web API with QNetworkAccessManager

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 525 Views 2 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
    NuclearPink
    wrote on last edited by
    #1
    This post is deleted!
    Pablo J. RoginaP raven-worxR 2 Replies Last reply
    0
    • N NuclearPink

      This post is deleted!

      Pablo J. RoginaP Offline
      Pablo J. RoginaP Offline
      Pablo J. Rogina
      wrote on last edited by
      #2

      @NuclearPink said in Trouble Logging into Web API with QNetworkAccessManager:

      connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(gotCookies(QNetworkReply*)));
      connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(networkReply(QNetworkReply*)));

      Any reason why you're connecting same signal to two different slots?

      Please be aware that order of slot execution is not guaranteed.

      You may want to connect one slot at a time (first gotCookies which inside disconnect and reconnects to networkReply() for instance, or just work with QNetworkReply::finished signal instead

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • N NuclearPink

        This post is deleted!

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

        @NuclearPink
        the curl command passes /tmp/cookies.txt what your Qt oode doesn't
        so whats its contents?

        Also check for OpenSSL errors and ensure that your application can find OpenSSL libs

        --- 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
        2
        • N Offline
          N Offline
          NuclearPink
          wrote on last edited by NuclearPink
          #4

          @Pablo-J-Rogina My intention there is just to split up two different kinds of responses that aren't related, so I'm not worried about order. The first slot just makes sure a login attempt is made only after cookies are retrieved (and is disconnected once they are), and the second prints out any replies from the server. If my way is bad practice I'll keep it in mind.

          @raven-worx I thought that QNetworkAccessManager mostly abstracts cookies which is why I don't try to send them manually. Printing out manager->cookieJar()->cookiesForUrl() in the gotCookies slot shows me that they're retrieved correctly.

          Here's a better version of the data that Qt is sending, retrieved from wireshark:

          POST /login.cgi HTTP/1.1
          Accept: */*
          Content-Type: multipart/form-data; boundary="boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw"
          MIME-Version: 1.0
          Cookie: AIROS_6872518A71F3=c3536a042ab27b9f4d549f1d047bcc1a; ui_language=en_US
          Content-Length: 298
          Connection: Keep-Alive
          Accept-Encoding: gzip, deflate
          Accept-Language: en-US,*
          User-Agent: Mozilla/5.0
          Host: 192.168.1.20
          
          --boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw
          Content-Disposition: form-data; name="username"
          
          ubnt
          --boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw
          Content-Disposition: form-data; name="password"
          
          password
          --boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw--
          
          

          So it looks like cookies are being sent.

          Do I still need to worry about SSL if I'm telling replies to ignore errors? I do a similar thing in curl with the -k option because the Ubiquiti radio uses a self-signed certificate that I haven't set up to accept yet.

          raven-worxR 1 Reply Last reply
          0
          • N NuclearPink

            @Pablo-J-Rogina My intention there is just to split up two different kinds of responses that aren't related, so I'm not worried about order. The first slot just makes sure a login attempt is made only after cookies are retrieved (and is disconnected once they are), and the second prints out any replies from the server. If my way is bad practice I'll keep it in mind.

            @raven-worx I thought that QNetworkAccessManager mostly abstracts cookies which is why I don't try to send them manually. Printing out manager->cookieJar()->cookiesForUrl() in the gotCookies slot shows me that they're retrieved correctly.

            Here's a better version of the data that Qt is sending, retrieved from wireshark:

            POST /login.cgi HTTP/1.1
            Accept: */*
            Content-Type: multipart/form-data; boundary="boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw"
            MIME-Version: 1.0
            Cookie: AIROS_6872518A71F3=c3536a042ab27b9f4d549f1d047bcc1a; ui_language=en_US
            Content-Length: 298
            Connection: Keep-Alive
            Accept-Encoding: gzip, deflate
            Accept-Language: en-US,*
            User-Agent: Mozilla/5.0
            Host: 192.168.1.20
            
            --boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw
            Content-Disposition: form-data; name="username"
            
            ubnt
            --boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw
            Content-Disposition: form-data; name="password"
            
            password
            --boundary_.oOo._MTE4NDAzNTA0MQ==MzIxMzA1Mjg1Mzk2MTkzODgw--
            
            

            So it looks like cookies are being sent.

            Do I still need to worry about SSL if I'm telling replies to ignore errors? I do a similar thing in curl with the -k option because the Ubiquiti radio uses a self-signed certificate that I haven't set up to accept yet.

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

            @NuclearPink said in Trouble Logging into Web API with QNetworkAccessManager:

            Here's a better version of the data that Qt is sending, retrieved from wireshark:

            so now compare it to the working request with curl.
            Then its clear where the difference is.

            --- 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

            • Login

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