Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //POSTing
- QUrl url("http://iichan.hk/cgi-bin/wakaba.pl/" + mtask.board + "/");
- QNetworkRequest request(url);
- request.setRawHeader("Host", "iichan.hk");
- request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:36.0) Gecko/20100101 Firefox/36.0");
- request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
- request.setRawHeader("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3");
- request.setRawHeader("Referer", "http://iichan.hk/" + mtask.board.toLatin1() + "/");
- request.setRawHeader("Cookie", "wakabastyle=Futaba");
- QHttpMultiPart *mp = new QHttpMultiPart;//(QHttpMultiPart::FormDataType);
- Tools::appendPart(mp, "task", "post");
- Tools::appendPart(mp, "name", ""); //name, must keep empty
- Tools::appendPart(mp, "link", ""); //must keep empty
- Tools::appendPart(mp, "nya1", ""); //must keep empty
- Tools::appendPart(mp, "nya2", ""); //email
- Tools::appendPart(mp, "nya3", mtask.subject.toUtf8().data()); //subject
- Tools::appendPart(mp, "nya4", mtask.text.toUtf8().data()); //text
- Tools::appendFile(mp, "file", mtask.pic);
- Tools::appendPart(mp, "captcha", captcha.toUtf8().data()); //captcha
- Tools::appendPart(mp, "postredir", "1");
- Tools::appendPart(mp, "password", mtask.password.toUtf8().data()); //password
- mreply = mnam->post(request, mp);
- mp->setParent(mreply.data());
- connect(mreply.data(), SIGNAL(finished()), this, SLOT(replyFinished()));
- //Reply received
- QTextStream in(data);
- in.setCodec("UTF-8");
- qDebug() << in.readAll(); //Always getting "<html><body><a href="/b/index.html">/b/index.html</a></body></html>"
- //Helpers
- bool appendFile(QHttpMultiPart *mp, const QByteArray &name, const QString &fileName, QByteArray type)
- {
- if (!mp || name.isEmpty() || fileName.isEmpty())
- return false;
- bool ok = false;
- QByteArray data = BDirTools::readFile(fileName, -1, &ok);
- if (!ok)
- return false;
- if (type.isEmpty()) {
- type = mimeType(data, &ok);
- if (!ok)
- return false;
- }
- QHttpPart part;
- QByteArray fn = QFileInfo(fileName).fileName().toUtf8();
- part.setHeader(QNetworkRequest::ContentDispositionHeader,
- "form-data; name=\"" + name + "\"; filename=\"" + fn + "\"");
- part.setHeader(QNetworkRequest::ContentTypeHeader, type);
- part.setBody(data);
- mp->append(part);
- return true;
- }
- bool appendPart(QHttpMultiPart *mp, const QByteArray &name, const QByteArray &value)
- {
- if (!mp || name.isEmpty())
- return false;
- QHttpPart part;
- part.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"" + name + "\"");
- part.setBody(value);
- mp->append(part);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement