[Qt /cookie] - How send post on website (phpbb3)



  • My english is low.

    I have problem:
    I can't send message on forum phpbb3.
    I can login. I can't send message.
    Login to forum is success. Sending a post is not doing.

    My source code:

    dialog.h
    @#ifndef DIALOG_H
    #define DIALOG_H

    #include <QDialog>
    #include <QNetworkAccessManager>
    #include <QNetworkRequest>
    #include <QNetworkReply>
    #include <QNetworkCookie>
    #include <QNetworkCookieJar>
    #include <QDebug>
    #include <QList>

    namespace Ui {
    class Dialog;
    }

    class Dialog : public QDialog
    {
    Q_OBJECT

    public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

    private:
    Ui::Dialog *ui;
    QNetworkAccessManager *manager;
    QList <QNetworkCookie> cookie;
    QList <QByteArray> listt;
    QNetworkRequest request;
    QNetworkReply *reply;
    QVariant var;
    QNetworkCookieJar *cookiejar;

    public slots:
    void mySlot(QNetworkReply *);
    };
    #endif // DIALOG_H@

    dialog.cpp
    @#include "dialog.h"
    #include "ui_dialog.h"

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);

    manager = new QNetworkAccessManager(this);
    cookiejar = new QNetworkCookieJar(manager);
    connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(mySlot(QNetworkReply*)));
    
    //login on www
    QByteArray postData;
    QUrl paare;
    request.setUrl(QUrl("http://127.0.0.1/ucp.php?mode=login"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded"));
    request.setRawHeader("User-Agent", "Firefox/3.0.10");
    paare.addQueryItem("username", "Moderator");
    paare.addQueryItem("password", "moderator");
    paare.addQueryItem("login", "");
    postData = paare.encodedQuery();
    reply = manager->post(request, postData);
    //end of login on www - effect: OK
    
    //send post on www
    paare.clear();
    postData.clear();
    request.setUrl(QUrl("http://127.0.0.1/posting.php?mode=reply&f=2&t=1"));
    paare.addQueryItem("message", "my message ...");
    paare.addQueryItem("post", "");
    postData = paare.encodedQuery();
    manager->post(request, postData);
    //end of send post on www - effect: fail
    

    }

    Dialog::~Dialog()
    {
    delete ui;
    }

    void Dialog::mySlot(QNetworkReply *e)
    {
    if( e->error() == QNetworkReply::NoError )
    {
    qDebug() << "OK!";
    }
    else
    {
    qDebug() << "ERROR! " << e->errorString();
    }
    }@

    It will help anyone? Thanks



  • Read through this thread: "PHP post":http://qt-project.org/forums/viewthread/26627/

    There is a RFC compatibility issue between PHP post and Qt Post :)


Log in to reply
 

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