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. QHttpMultiPart - failing to post parameters to a php script
Forum Updated to NodeBB v4.3 + New Features

QHttpMultiPart - failing to post parameters to a php script

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 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.
  • M Offline
    M Offline
    Mr-Merlin
    wrote on last edited by
    #1

    Hi,

    I have a class that uses a QNetworkRequest object to send data to a php script on a server, which would then process the data and post back a reply.

    Part of the code to post a parameter was this: -
    @
    QByteArray& data = netPacket->data;

    QString bound="---Boundary0xbfffeec9---";
    data = QByteArray(QString("--"+bound+"\r\n").toAscii());
    data += "Content-Disposition: form-data; name=\"userfilename\"\r\n\r\n";
    data += userfilename+ "\r\n";
    data += QString("--" + bound + "\r\n").toAscii();
    ...
    

    QNetworkAccessManager* m_pHttp;
    netPacket->pReply = m_pHttp->post(netRequest,data);
    @

    That worked as expected and "userfilename" appears as a posted parameter to the php script.

    I now need to change the code to use QHttpMultiPart, as I need to upload files with the data and don't want to have to load them in memory, but the php script never seems to get any posted parameters.

    I'm doing the following: -
    @
    QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::RelatedType);
    QHttpPart textPart1;
    textPart1.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain"));
    textPart1.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name="userfilename""));
    textPart1.setBody(userfilename.toUtf8());
    multiPart->append(textPart1);
    ...
    ...
    m_pHttp->post(request, multiPart);
    netPacket->pReply = m_pHttp->post(request, multiPart);
    @

    Can anyone please explain to me where I'm going wrong and why "userfilename" isn't being posted to the web server? The php script is being called, but $_POST in the php script is now empty.

    Thanks.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      oliver_kranz
      wrote on last edited by
      #2

      There is a bug in QHttpMultiPart.

      https://bugreports.qt-project.org/browse/QTBUG-25429

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

        I got the same problem using QHttpMultiPart in uploading files via form....

        I googled and found "FormPost":http://www.tuckdesign.com/sources/Qt instead and it worked like a charm. I only modified it to not become a plugin since it was designed as a plugin.

        You may wanna try to use it.

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        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