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. Sent the data instead of relying on the "submit" button of the html
Forum Updated to NodeBB v4.3 + New Features

Sent the data instead of relying on the "submit" button of the html

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k 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.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    snippet of the website
    <html>

    <form action="index.php" method="post" enctype="multipart/form-data" >
    <td><input type="file" name="upfile" size="35" /></td>
    <td><input type="submit" value="send" /></td>
    </form>

    </html>

    I want to select and send some files onto a server without manually click on
    the "file" and "send" button.Is this possible?

    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      Send a HTTP post request programmatically with QNetworkAccessManager:
      http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html#post-3
      http://qt-project.org/doc/qt-4.8/qhttpmultipart.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #3

        Thanks, looks like this is what I need.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stereomatching
          wrote on last edited by
          #4

          Do some test and stuck, don't understand how to use it properly

          "The website I want to post":http://2cat.or.tl/~tedc21thc/live/index.php?res=549796

          The html I think it is related to my objective

          <td><input type="text" name="sub" size="35">
          <input type="submit" value="送信する" /></td>

          <td><textarea name="com" cols="48" rows="4" wrap=soft></textarea></td>

          @
          class postToKomica : public QObject
          {
          Q_OBJECT

          public:
          void sendTextToKomica()
          {
          QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

              //set the text?
              QHttpPart textPart;
              textPart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/plain"));
              textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"com\""));
              textPart.setBody("this is a good animation");
          
              //"click" the submit button?
              QHttpPart sendPart;
              sendPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"submit\""));
          
              multiPart->append(textPart);
              multiPart->append(sendPart);
          
              QUrl url("http://2cat.or.tl/~tedc21thc/live/index.php?res=549796");
              QNetworkRequest request(url);
          
              QNetworkAccessManager *manager = new QNetworkAccessManager(this);
              QNetworkReply *reply = manager->post(request, multiPart);
              multiPart->setParent(reply); // delete the multiPart with the reply
          
              connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finished(QNetworkReply*)));
          }
          

          private slots:
          void finished(QNetworkReply *reply)
          {
          qDebug() << reply->error();
          }

          };
          @

          The reply is "0".
          I only know some basic about html,javascript and network
          What do I need to know before I can "post" the data onto
          the website with the help of QHttpMultiPart and QHttpPart?

          Thanks

          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