QT 获取服务器返回的Set-cookie

2020-02-02  本文已影响0人  tsslisimin
        QNetworkAccessManager *net_manager_ = new QNetworkAccessManager(this);
        connect(net_manager_, SIGNAL(finished(QNetworkReply*)), receiver, SLOT(onNetworkFinished(QNetworkReply*)));

void LoginForm::onNetworkFinished(QNetworkReply * reply)
{


    QString jsonData = reply->readAll();
        QVariant variantCookies = reply->header(QNetworkRequest::SetCookieHeader);
        QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(variantCookies);

        QNetworkCookie cookie=cookies.at(0);

        QString DataAsString =cookie.toRawForm();//toRawForm方法是转换为QByteArray
        qDebug() <<variantCookies <<variantCookies.toString() << "   ---- " <<cookies.size()<<" "<<cookies.at(0)<<" "<<DataAsString;
}
上一篇下一篇

猜你喜欢

热点阅读