reply->error() != QNetworkReply::NoError
,回复会返回空身内容, 但实际上响应有内容。
我怎么读?
void MainWindow::on_pushButton_clicked()
{
manager = new QNetworkAccessManager(this);
connect( manager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(replyFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://...")));
}
void MainWindow::replyFinished(QNetworkReply* reply)
{
if (reply->error() == QNetworkReply::NoError)
{
QByteArray content= reply->readAll();
QDebug() << QString body(content); // ok
} else {
QByteArray content= reply->readAll();
QDebug() << QString body(content); //empty, but must be exist
}
}