0

我的英语很低。

我有问题:我无法在论坛 phpbb3 上发送消息。我可以登录。我无法发送消息。登陆论坛就成功了。发帖是不行的。

我的源代码:

对话框.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

对话框.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();
    }
}

它会帮助任何人吗?谢谢


#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
    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
}

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

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

    //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
}

仍然不起作用:/消息未发送。

qDebug() << e->realAll(); ...提交的表格无效。尝试再次提交。... 为什么?

4

1 回答 1

0

您在发送登录请求后立即发布消息,在您完成经理之前。因此,当您发送消息请求时,您的登录会话将不会启动。将您的消息发送代码放入 mySlot()

于 2013-05-11T12:48:26.700 回答