Qt 在web服务的Http Post调用中未获得正确响应

Qt 在web服务的Http Post调用中未获得正确响应,qt,symfony1,Qt,Symfony1,我正在使用HTTPPOST方法调用一个Web服务,并得到下面的文本作为响应 HTTP/1061.1061 1061我已经在调试中打印了QHttpResponseHeader 但在实际情况下,它应该返回错误代码或xml。所以请告诉我在下面的代码中我做错了什么 //.cpp file code MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { qDebug() <

我正在使用HTTPPOST方法调用一个Web服务,并得到下面的文本作为响应

HTTP/1061.1061 1061我已经在调试中打印了QHttpResponseHeader

但在实际情况下,它应该返回错误代码或xml。所以请告诉我在下面的代码中我做错了什么

//.cpp file code 
 MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
  qDebug() << "start";
  http = new QHttp(this); // http declared as a member of MainWindow class
  connect(http, SIGNAL(requestFinished(int,bool)), SLOT(replyFinished(int, bool)));

  QByteArray data;//(QString("--" + boundary + "\r\n").toAscii());
  data += "Content-Disposition: form-data; name=\"action\"\r\n\r\n";

  data += "Content-Type: text/xml;charset=\"utf-8\"\r\n\r\n";

  data += QString("<LoginData><IMEI>test123</IMEI><email>a@a.com</email></LoginData>").toAscii();
  data += "\r\n";

  data += "Content-Disposition: form-data; name=\"description\"\r\n\r\n";

  data += "\r\n";

  QHttpRequestHeader header("Content-Type","application/soap+xml;charset=UTF-8");
  header.setValue("Host", "http://xxx.com/restwebservice/ForgotPassword.ashx?");
  header.setValue("Accept-Language", "en-us,en;q=0.5");
  header.setValue("Keep-Alive", "300");
  header.setValue("Connection", "keep-alive");
  header.setValue("Referer", "http://xxx.com/restwebservice/ForgotPassword.ashx?");

  qDebug() << "the sent data is :" + data;
  http->setHost("http://xxx.com/restwebservice/ForgotPassword.ashx?");
  http->request(header, data);

  ui->setupUi(this);
}
缝隙法

void MainWindow :: replyFinished(int , bool)
{
    QHttpResponseHeader responce = http->lastResponse();
    qDebug()<<"reply is :" + responce.toString();
}
QHttp已被弃用,只是为了向后兼容才保留在这里


对于新代码,您应该使用QNetworkAccessManager/QNetworkRequest/QnetworkReply

和其他一件事……如果我想使用web服务上载图像,那么也将使用此类,或者我必须使用QHttp。相同的类。您可以使用QNetworkAccessManager::post来上传数据。