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. Encoding a QByteArray into application/x-www-form-urlencoded HTTP POST format?
Forum Updated to NodeBB v4.3 + New Features

Encoding a QByteArray into application/x-www-form-urlencoded HTTP POST format?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.0k 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.
  • J Offline
    J Offline
    jonwil
    wrote on last edited by jonwil
    #1

    Is there a function/class in QT 4.x (any version) that can take a QByteArray and encode it into the application/x-www-form-urlencoded HTTP POST url format? (with spaces replaced by + signs etc) I dont mind taking it from Webkit or somewhere like that if it exists there.
    I dont need multi-part support or anything like that, just the simple encoding function.

    I found http://code.qt.io/cgit/qt/qt.git/commit/?id=8ad504b31a53ea2a7993f5217c68d0c4aa203b2d but that is code for feeding data in and having it converted to the right format when it gets sent over the network rather than just a simple conversion function (unless I missed something).

    I also found QByteArray::toPercentEncoding but that doesn't encode things the correct way for x-www-form-urlencoded (which needs e.g. spaces to be encoded as + signs and not %20)

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jonwil
      wrote on last edited by jonwil
      #2

      After some searching of the QT source tree I have (some version of QT 4.7 as it happens) I found a function called FormDataBuilder::encodeStringAsFormData and was able to copy and modify it to do what I needed it to do so and it now works correctly.
      Spaces are encoded as + signs, other things are encoded as the correct % characters and newlines are properly encoded.

      VRoninV 1 Reply Last reply
      1
      • J jonwil

        After some searching of the QT source tree I have (some version of QT 4.7 as it happens) I found a function called FormDataBuilder::encodeStringAsFormData and was able to copy and modify it to do what I needed it to do so and it now works correctly.
        Spaces are encoded as + signs, other things are encoded as the correct % characters and newlines are properly encoded.

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        @jonwil Could you post the solution so future programmers-in-distress can benefit from it?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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