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. Is there a code sample for HTTP/2 client?
Forum Updated to NodeBB v4.3 + New Features

Is there a code sample for HTTP/2 client?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 347 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.
  • F Offline
    F Offline
    fafnir
    wrote last edited by fafnir
    #1

    I am trying to write a server-side application (console app, running on Linux, controlled with systemd) to send APNs push notifications from my server to iOS/MacOS apps.
    Apple requires the use of HTTP/2.
    Authentication, including JWT token refresh, payload formatting or any other requirements to send notifications are not a problem for me: I've done this before in C#. But now I need to do it in Qt 6, and that's where I got stuck.

    Is there a code sample for establishing an HTTP/2 client connection and sending a message to a server?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote last edited by
      #3

      QNetworkRequest::setHttp2Configuration() before making the first request to the Apple server looks promising.

      1 Reply Last reply
      1
      • F Offline
        F Offline
        fafnir
        wrote last edited by
        #2

        Additional information: as per https://developer.apple.com/documentation/usernotifications/sending-push-notifications-using-command-line-tools#Send-a-push-notification-using-a-JSON-web-token-JWT , a curl command looks like this:

        curl -v
        --header "apns-topic: $TOPIC"
        --header "apns-push-type: alert"
        --header "authorization: bearer $AUTHENTICATION_TOKEN"
        --data '{"aps":{"alert":"test"}}'
        --http2 https://${APNS_HOST_NAME}/3/device/${DEVICE_TOKEN}

        It's the "-http2 [...]" part that I am trying to figure out how to write using QNetworkAccessManager.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote last edited by
          #3

          QNetworkRequest::setHttp2Configuration() before making the first request to the Apple server looks promising.

          1 Reply Last reply
          1
          • F Offline
            F Offline
            fafnir
            wrote last edited by
            #4

            I read the information about available classes in the Qt docs, of course.
            For example, in the method you linked to, there is the following:
            "Note: HTTP/2 multiplexes several streams in a single HTTP/2 connection. This implies that QNetworkAccessManager will use the configuration found in the first request from a series of requests sent to the same host."
            This raises more questions, such as: is there an example of how to start several streams on a single connection?

            1 Reply Last reply
            0
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote last edited by
              #5

              I think that you can ignore the "--http2" switch (it's a red herring), since you're connecting via https:// anyway.
              (i.e. whether the request goes over http1 over http2 is immaterial, the important thing is the https://)

              1 Reply Last reply
              1
              • F fafnir has marked this topic as solved
              • F Offline
                F Offline
                fafnir
                wrote last edited by
                #6

                The solution was indeed the QHttp2Configuration.
                Thank you!

                1 Reply Last reply
                0
                • F fafnir has marked this topic as solved
                • F fafnir has marked this topic as solved

                • Login

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