Advertisement
Guest User

Untitled

a guest
Mar 19th, 2015
1,710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. //POSTing
  2. QUrl url("http://iichan.hk/cgi-bin/wakaba.pl/" + mtask.board + "/");
  3. QNetworkRequest request(url);
  4. request.setRawHeader("Host", "iichan.hk");
  5. request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:36.0) Gecko/20100101 Firefox/36.0");
  6. request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  7. request.setRawHeader("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3");
  8. request.setRawHeader("Referer", "http://iichan.hk/" + mtask.board.toLatin1() + "/");
  9. request.setRawHeader("Cookie", "wakabastyle=Futaba");
  10. QHttpMultiPart *mp = new QHttpMultiPart;//(QHttpMultiPart::FormDataType);
  11. Tools::appendPart(mp, "task", "post");
  12. Tools::appendPart(mp, "name", ""); //name, must keep empty
  13. Tools::appendPart(mp, "link", ""); //must keep empty
  14. Tools::appendPart(mp, "nya1", ""); //must keep empty
  15. Tools::appendPart(mp, "nya2", ""); //email
  16. Tools::appendPart(mp, "nya3", mtask.subject.toUtf8().data()); //subject
  17. Tools::appendPart(mp, "nya4", mtask.text.toUtf8().data()); //text
  18. Tools::appendFile(mp, "file", mtask.pic);
  19. Tools::appendPart(mp, "captcha", captcha.toUtf8().data()); //captcha
  20. Tools::appendPart(mp, "postredir", "1");
  21. Tools::appendPart(mp, "password", mtask.password.toUtf8().data()); //password
  22. mreply = mnam->post(request, mp);
  23. mp->setParent(mreply.data());
  24. connect(mreply.data(), SIGNAL(finished()), this, SLOT(replyFinished()));
  25.  
  26. //Reply received
  27. QTextStream in(data);
  28. in.setCodec("UTF-8");
  29. qDebug() << in.readAll(); //Always getting "<html><body><a href="/b/index.html">/b/index.html</a></body></html>"
  30.  
  31. //Helpers
  32.  
  33. bool appendFile(QHttpMultiPart *mp, const QByteArray &name, const QString &fileName, QByteArray type)
  34. {
  35.     if (!mp || name.isEmpty() || fileName.isEmpty())
  36.         return false;
  37.     bool ok = false;
  38.     QByteArray data = BDirTools::readFile(fileName, -1, &ok);
  39.     if (!ok)
  40.         return false;
  41.     if (type.isEmpty()) {
  42.         type = mimeType(data, &ok);
  43.         if (!ok)
  44.             return false;
  45.     }
  46.     QHttpPart part;
  47.     QByteArray fn = QFileInfo(fileName).fileName().toUtf8();
  48.     part.setHeader(QNetworkRequest::ContentDispositionHeader,
  49.                    "form-data; name=\"" + name + "\"; filename=\"" + fn + "\"");
  50.     part.setHeader(QNetworkRequest::ContentTypeHeader, type);
  51.     part.setBody(data);
  52.     mp->append(part);
  53.     return true;
  54. }
  55.  
  56. bool appendPart(QHttpMultiPart *mp, const QByteArray &name, const QByteArray &value)
  57. {
  58.     if (!mp || name.isEmpty())
  59.         return false;
  60.     QHttpPart part;
  61.     part.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"" + name + "\"");
  62.     part.setBody(value);
  63.     mp->append(part);
  64.     return true;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement