Answer the question
In order to leave comments, you need to log in
How to send request headers Cookie in Qt?
mainwindow.h
private:
QList<QNetworkCookie> cookies;
cookie.setName("visible");
cookie.setValue("0");
cookie.setDomain("site.ru");
cookie.setPath("/dev/mobile");
cookie.setExpirationDate(QDateTime().addYears(9999));
cookies << cookie;
void MainWindow::sendRequest(const QString& urlString){
log("sendRequest");
QTimer timer;
timer.setInterval(3000);
timer.setSingleShot(true);
QEventLoop loop;
currentUrlString = urlString;
url->setUrl(urlString);
request->setUrl(*url);
request->setHeader(QNetworkRequest::CookieHeader, qVariantFromValue(cookies));
qDebug() << "Cookie:" << request->header(QNetworkRequest::CookieHeader).toList();
QNetworkReply* reply = manager->get(*request);
QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
QObject::connect(&timer, &QTimer::timeout, reply, &QNetworkReply::abort);
timer.start();
loop.exec();
}
qDebug() << "Cookie:" << request->header(QNetworkRequest::CookieHeader).toList();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question