View Full Version : QWebView cookie issue when performing post operation

30th August 2014, 12:00
I'm probably trying to go about this the wrong way, but I've been trying to automatically sign a user into a website using the load function of QWebView to perform the post operation.
The problem is, upon signing in I'm told that I'm required to accept cookies to sign in and I'm just not sure how to resolve this issue.

Here's the current code responsible for performing the post operation (with some minor alterations for privacy's sake).

QNetworkAccessManager *m;
QNetworkRequest r;
QNetworkCookieJar *c = new QNetworkCookieJar();
QByteArray payload;
payload.append("login=" + username + "&register=0&password=" + password + "&remember=1&cookie_check=1&_xfToken=&redirect=http://website.com/shoutbox/popup");
r.attribute(QNetworkRequest::CookieSaveControlAttr ibute, QVariant(true));
r.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8");
r.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
r.setRawHeader("Accept-Language", "en-US,en;q=0.5");
r.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(QString::number(payload.length())));
r.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
r.setRawHeader("Referer", "http://website.com/login");
r.setRawHeader("Host", "www.website.com");
m = new QNetworkAccessManager();
ui->webView->load(r, QNetworkAccessManager::PostOperation, payload);

Could I just rewrite the post request separate from the web view, handle the response manually and then pass the cookies to the web view or is there a way to get this working as it is?
I'm feel like I'm just missing something really obvious. >_>

Thank you.