QNetworkReply and 302 Found code
I am developing an application that uses the Qt Webkit. I have this code :
Manager = new QNetworkAccessManager();
QObject::connect(Manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(finished_login(QNetworkReply *)));
params.addQueryItem("username", *(Config->get_user_forum()) );
QNetworkReply *test = Manager->post(request,params.encodedQuery());
void SignalHandler::finished_login(QNetworkReply *reply)
QObject::disconnect(Manager, SIGNAL(finished(QNetworkReply *)),this,SLOT(finished_login(QNetworkReply *)));
QByteArray *temp = new QByteArray(reply->readAll());
This code should make the login in forums based on phpbb3. It works for several forums, but it doesn't work for a forum. The problem is that the reply->readAll() return an empty QByteArray. The same code works for others forum, and it returns the html page after the login.
I tried to debug the problem with a network analyzer and I saw that the server responds with the http response status code 302. It seems a sort of redirect, but I'm not sure. How can I handle this ? Is there a workaround ? Sorry for my english and sorry for my lack of experience.
Follow redirects. From "QNetworkReply doc:":http://qt-project.org/doc/qt-5.0/qtnetwork/qnetworkreply.html Note: When the HTTP protocol returns a redirect no error will be reported. You can check if there is a redirect with the QNetworkRequest::RedirectionTargetAttribute attribute.
example can be found "here":http://developer.nokia.com/Community/Wiki/Handling_an_HTTP_redirect_with_QNetworkAccessManager.
[quote author="raven-worx" date="1376389368"]example can be found "here":http://developer.nokia.com/Community/Wiki/Handling_an_HTTP_redirect_with_QNetworkAccessManager.[/quote]
I've already see the example but it's a little bit different from my case. To make a successfull login I have to use post request, after that I usually obtain a page and inside the html code I extract a parameter called "ssid". This "ssid" is used in the next request like an authentication token. I'm not sure that the example can help me bacause it uses a get request and without this "ssid" I'll never login.
I don't know if I was clear. Now I'm trying to join and adapt the example code, but I'm not sure that it will work. Thank for the help and thank for any reply.
the example just shows how to handle the redirect. It's independent if POST or GET.
If you detect a redirect (example) you do the same request like you did initially but only to the new redirected url.