Hi to all,
I'm trying to post a form after the login on the web(a classic login.php page), so I've divided the tasks into two step(two methods im my class) and I've ran those sequential(Login and Post) but I've had at first step a correct feedback instead on posting the form I've recieved an error like not logged in type. So, I've joined the tasks into a single method but it doesn't work yet. Maybe the code will explain better:

Qt Code:
  1. void MainWindow::postData()
  2. {
  3. QString url;
  4. QString host;
  5. QByteArray username("username=myname&password=mypassword");
  6.  
  7. userAgentS = "My App";
  8. encodingS = "utf-8";
  9. charCrLf = "\r\n";
  10.  
  11. url = "http://www.xyz.com/login.php";
  12. refererS = "http://www.xyz.com/login_page.php";
  13.  
  14. host = url.right(url.length() - url.indexOf("://") - 3);
  15. host = host.left(host.indexOf("/"));
  16.  
  17. QNetworkAccessManager * http = new QNetworkAccessManager(this);
  18. connect(http, SIGNAL(finished(QNetworkReply *)), this,
  19. SLOT(readData(QNetworkReply *)));
  20.  
  21. QNetworkRequest request;
  22. request.setRawHeader("Host", host.toAscii());
  23. request.setRawHeader("User-Agent", userAgentS.toAscii());
  24. request.setRawHeader("Referer", refererS.toAscii());
  25.  
  26. QString contentType = "application/x-www-form-urlencoded";
  27.  
  28. request.setHeader(QNetworkRequest::ContentTypeHeader, contentType.toAscii());
  29. request.setHeader(QNetworkRequest::ContentLengthHeader,
  30. QVariant(username.size()).toString());
  31. request.setUrl(QUrl(url));
  32.  
  33. http->post(request, username);
  34.  
  35. /*-------------------------------------------------------------------------*/
  36. /* Posting the Form */
  37.  
  38. addField("project_id","1");
  39. addField("category","GUI");
  40. addField("summary","Prova");
  41. addField("description","Indovina che Bug è?");
  42.  
  43. refererS = "http://www.xyz.com/report_page.php";
  44. url = "http://www.xyz.com/report.php";
  45. host = url.right(url.length() - url.indexOf("://") - 3);
  46. host = host.left(host.indexOf("/"));
  47.  
  48. qsrand(QDateTime::currentDateTime().toTime_t());
  49. QString b = QVariant(qrand()).toString() + QVariant(qrand()).toString()
  50. + QVariant(qrand()).toString();
  51. QString boundary = "---------------------------"+b;
  52. QString endBoundary = charCrLf + "--" + boundary + "--" + charCrLf;
  53. contentType = "multipart/form-data; boundary=" + boundary;
  54. boundary = "--" + boundary + charCrLf;
  55. QByteArray bond = boundary.toAscii();
  56. QByteArray send;
  57. bool first = true;
  58.  
  59. for (int i=0; i < fieldNames.size(); i++)
  60. {
  61. send.append(bond);
  62. if (first)
  63. {
  64. boundary = charCrLf + boundary;
  65. bond = boundary.toAscii();
  66. first = false;
  67. }
  68.  
  69. send.append(QString("Content-Disposition: form-data; name=\"" +
  70. fieldNames.at(i) + "\"" + charCrLf).toAscii());
  71.  
  72. if (encodingS == "utf-8")
  73. {
  74. // send.append(QString("Content-Transfer-Encoding: 8bit" +
  75. // charCrLf).toAscii());
  76. send.append(charCrLf.toAscii());
  77. send.append(strToEnc(fieldValues.at(i)));
  78. }
  79. }
  80.  
  81. send.append(endBoundary.toAscii());
  82.  
  83. request.setRawHeader("Host", host.toAscii());
  84. request.setRawHeader("User-Agent", userAgentS.toAscii());
  85. request.setRawHeader("Referer", refererS.toAscii());
  86.  
  87. request.setHeader(QNetworkRequest::ContentTypeHeader, contentType.toAscii());
  88. request.setHeader(QNetworkRequest::ContentLengthHeader,
  89. QVariant(send.size()).toString());
  90. request.setUrl(QUrl(url));
  91.  
  92. http->post(request, send);
  93. }
  94.  
  95. void MainWindow::readData(QNetworkReply * r)
  96. {
  97. data = r->readAll();
  98. ui->textEdit->append(QString(data).toUtf8());
  99. qDebug() << "readData eror(): " << r->error();
  100. }
To copy to clipboard, switch view to plain text mode 

Thanks!