美文网首页
QT 获取服务器返回的Set-cookie

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

作者: tsslisimin | 来源:发表于2020-02-02 18:30 被阅读0次
    • 设置槽函数
            QNetworkAccessManager *net_manager_ = new QNetworkAccessManager(this);
            connect(net_manager_, SIGNAL(finished(QNetworkReply*)), receiver, SLOT(onNetworkFinished(QNetworkReply*)));
    
    
    • 其中cookies即为服务器返回的cookie
    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;
    }
    

    相关文章

      网友评论

          本文标题:QT 获取服务器返回的Set-cookie

          本文链接:https://www.haomeiwen.com/subject/jpiqxhtx.html