Thanks all. I did 2 mistakes one was not encoding the data to be sent and other was (silly) by not specifying the correct URL of the page. The code that works for me is below:


Qt Code:
  1. uploadmanager::uploadmanager()
  2. {
  3. connect(&manager, SIGNAL(finished(QNetworkReply*)),
  4. SLOT(uploadFinished(QNetworkReply*)));
  5. }
  6.  
  7.  
  8. void uploadmanager::doUpload()
  9. {
  10. QString message_d = QString("Unable to open file");
  11. args<<"E:\\SMS\\spam_freq.csv";
  12.  
  13. foreach (QString arg, args) {
  14.  
  15. QFile file(arg);
  16.  
  17. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
  18. {
  19. QMessageBox::information(this, "Error", message_d);
  20. return;
  21. }
  22.  
  23. file.open(QIODevice::ReadOnly | QIODevice::Text);
  24. QByteArray data(file.readAll());
  25. QByteArray sdata;
  26. QUrl params;
  27. params.addQueryItem("data", data); //I wasn't encoding the data, one error was here
  28. sdata.append(params.toString());
  29.  
  30.  
  31. file.close();
  32.  
  33.  
  34.  
  35. QNetworkRequest request;
  36.  
  37. request.setUrl(QUrl("http://myserv.com/smsspam/smsspam.php")); // i committed a silly blunder here by not including th php page in URL ( which i came to know by checking the reply content)
  38.  
  39.  
  40. request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
  41.  
  42.  
  43. QNetworkReply *reply = manager.post(request, sdata);
  44. currentUploads.append(reply);
  45. }
  46.  
  47. }
  48.  
  49. void uploadmanager::uploadFinished(QNetworkReply *reply)
  50. {
  51.  
  52. if (reply->error())
  53. {
  54. QByteArray response = reply->readAll();
  55. QFile file_spf("E:\\SMSAin\\dlog.txt");
  56. file_spf.open(QIODevice::WriteOnly | QIODevice::Text);
  57. QTextStream spf_in(&file_spf);
  58. spf_in<<response;
  59.  
  60. QString message_er = QString("Error in Upload");
  61. QMessageBox::information(this, "Err", message_er);
  62. }
  63. else
  64. {
  65. QString message_d = QString("Upload Complete");
  66. QMessageBox::information(this, "Upload Complete", message_d);
  67.  
  68. }
  69.  
  70. currentUploads.removeAll(reply);
  71. reply->deleteLater();
  72.  
  73. if (currentUploads.isEmpty())
  74. return;
  75.  
  76. }
To copy to clipboard, switch view to plain text mode