Issues issuing POST request to QWebView



  • I'm currently trying to issue a POST request to QWebView in order to sign in to a web site automatically.

    Below is the POST request I caught using my web debugger:
    @POST http://www.forum.com/login/login HTTP/1.1
    Host: www.forum.com
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    Referer: http://www.forum.com/login/
    Cookie: ...
    Connection: keep-alive
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 127

    login=username&register=0&password=password&remember=1&cookie_check=1&_xfToken=&redirect=http://www.forum.com/@

    Now here is the code I've written:
    @QNetworkRequest request;
    QByteArray payload;
    request.setUrl(QUrl("http://forum.com/login/login"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    payload.append("login=" + username + "&register=0&password=" + password + "&remember=1&cookie_check=1&_xfToken=&redirect=http://forum.com/someotherpage");
    ui->webView->load(request, QNetworkAccessManager::PostOperation, payload);@

    The POST request gets sent and seems as though it should work, but I get a 301 moved permanently in response before my QWebView tries to simply load the "http://forum.com/login/login" page (which is a problem since you're just presented with a page telling you that the function is available via POST only).

    I'd appreciate any advice you have may have to share. There's probably a better way to go about accomplishing this and I'm probably just missing something stupidly simple...that's usually how it is. All that matters to me is being able to sign in via POST and being able to use the session in a web view.

    Anyway, let me know if you need any other information and thanks for reading. n_n



  • Nevermind. Just had to fix the POST request headers. However, I'm now faced with the issue of cookies. Once I'm redirected after the post request the site tells me that cookies are required.

    Any tips on how to go about handling cookies in this situation? xD
    If not, I'll probably get it working eventually. :P


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.