QT 获取服务器返回的Set-cookie
2020-02-02 本文已影响0人
tsslisimin
- 设置槽函数
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;
}