我的英语很低。
我有问题:我无法在论坛 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(); ...提交的表格无效。尝试再次提交。... 为什么?