QNetworkReply从不发出完成的信号

时间:2017-12-28 05:44:33

标签: c++ qt

我正在编写一个简单的qt网络应用程序。我尝试从QNetworkReply读取数据,但似乎完成的信号从未发出。会发生什么?

QByteArray utils::Login(QString account)
{
    QNetworkAccessManager* manager = new QNetworkAccessManager();
    QNetworkRequest* request = new QNetworkRequest();
    request->setUrl(QUrl(Urls::loginUrl));

    request->setRawHeader("Host", "10.136.2.5");
    request->setRawHeader("Referer", "http://10.136.2.5/jnuweb/");
    request->setRawHeader("Content-Type", "application/json; charset=utf-8");
    request->setRawHeader("Connection", "keep-alive");
    request->setRawHeader("X-Requested-With", "XMLHttpRequest");
    request->setRawHeader("Accept", "*/*");
    request->setRawHeader("Accept-Encoding", "deflate");

    QJsonObject* requestContent = new QJsonObject();
    requestContent->insert("user", QJsonValue(account));
    requestContent->insert("password", QJsonValue(Urls::initPassword));

    QNetworkReply* reply = manager-> post(*request, QJsonDocument(*requestContent).toJson(QJsonDocument::Compact));

    QObject::connect(reply, &QNetworkReply::finished, [=]()
    {
        QList<QPair<QByteArray, QByteArray>> responses = reply -> rawHeaderPairs();
        qDebug() << responses;
    });
}

0 个答案:

没有答案