2012-03-09 34 views
0

我打电话使用HTTP POST方法和响应得到下面的文本web服务没有得到在Web服务的HTTP POST调用适当的响应

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>[email protected]</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(); 
} 

回答

0

QHttp做错了已被废弃,只还在这里向后兼容性。

对于新的代码,你应该使用QNetworkAccessManager/QNetworkRequest/QnetworkReplyhttp://qt-project.org/doc/qt-4.8/QNetworkAccessManager.html#details

+0

感谢名单的人,它的工作.... – Rajesh 2012-03-09 12:56:07

+0

还有一件事....如果我想使用Web服务上传的图像,然后也将使用这个类或我必须使用QHttp。 – Rajesh 2012-03-09 13:17:19

+1

相同的类。你可以使用QNetworkAccessManager :: post()和你的数据上传。 – Koying 2012-03-09 13:19:36