Sent the data instead of relying on the "submit" button of the html
-
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
-
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 -
Thanks, looks like this is what I need.
-
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_OBJECTpublic:
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