...тут идет стандартная чать заголовка...Content-Length: 43\r\nLine-based text data: application/x-www-form-urlencoded login=1234567&passwd=1234567
...тут идет стандартная чать заголовка...Content-Length: 43\r\nMedia Type: application/x-www-form-urlencoded (43 bytes)
QByteArray ba("login=1234567&passwd=1234567"); QString url = QString("/login.php"); header = QHttpRequestHeader("POST", url, 1, 1); header.setValue("Host", "site.ru"); header.setValue("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; ru; rv:1.9.0.10) Gecko/2009042809 GranParadiso/3.0.10"); header.setValue("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); header.setValue("Accept-Language", "ru,en-us;q=0.7,en;q=0.3"); header.setValue("Accept-Encoding", "gzip,deflate"); header.setValue("Keep-Alive", "115"); header.setValue("Connection", "keep-alive"); header.setValue("Referer", "http://site.ru"); header.setValue("Content-Type", "aplication/x-www-form-urlencoded"); header.setValue("Content-Length", QString(ba.length())); QHttp::ConnectionMode mode = QHttp::ConnectionModeHttp; http->setHost("site.ru",mode); http->request(header,ba);
C++ (Qt)void Functions::HTTPHEADERS(QNetworkReply *reply){ if (!SHOWHEADERS) return; qDebug() << endl << reply->url(); qDebug() << "Request headers: "; QList<QByteArray> reqHeaders = reply->request().rawHeaderList(); //QList<QByteArray> reqHeaders = request.rawHeaderList(); foreach (QByteArray reqName, reqHeaders) { QByteArray reqValue = reply->request().rawHeader(reqName); //QByteArray reqValue = request.rawHeader(reqName); qDebug() << reqName << ": " << reqValue; } qDebug() << "Reply headers: "; QList<QByteArray> reqHeadersReply = reply->rawHeaderList(); foreach( QByteArray reqName, reqHeadersReply ) { QByteArray reqValue = reply->rawHeader( reqName ); qDebug() << reqName << ": " << reqValue; }}
#ifndef WINDOW_H#define WINDOW_H#include <QMainWindow>#include <QUrl>#include <QWebElement>#include <QNetworkReply>QT_BEGIN_NAMESPACEclass QTreeWidgetItem;QT_END_NAMESPACE//! [Window class definition]#include "ui_window.h"class MyAccessManager : public QNetworkAccessManager{ Q_OBJECT virtual QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data) { emit sendMyPost(data); return QNetworkAccessManager::post(request,data); } signals: void sendMyPost(QString string);};class Window : public QMainWindow, private Ui::Window{ Q_OBJECTpublic: Window(QWidget *parent = 0); void setUrl(const QUrl &url); MyAccessManager *maneger; bool RecStatus;public slots: void on_webView_loadFinished(); void getMyPost(QString string); void showPage(QNetworkReply *replay);private: void examineChildElements(const QWebElement &parentElement, QTreeWidgetItem *parentItem);private slots: void on_pushButton_Pause_clicked(); void on_pushButton_Rec_clicked(); void on_pushButton_clicked();};//! [Window class definition]#endif
#include <QtGui>#include <QtWebKit>#include "window.h"//! [Window constructor]Window::Window(QWidget *parent) : QMainWindow(parent){ setupUi(this); maneger = new MyAccessManager; connect(maneger,SIGNAL(sendMyPost(QString)), this,SLOT(getMyPost(QString))); connect(maneger, SIGNAL(finished(QNetworkReply*)), this, SLOT(showPage(QNetworkReply*))); webView->page()->settings()->setAttribute(QWebSettings::PluginsEnabled, true); webView->page()->setNetworkAccessManager(maneger); //webView->setHtml(data);}//! [Window constructor]//! [set URL]void Window::setUrl(const QUrl &url){ RecStatus = false; webView->setUrl(url);}//! [set URL] //! [begin document inspection]void Window::on_webView_loadFinished(){ treeWidget->clear(); QWebFrame *frame = webView->page()->mainFrame(); QWebElement document = frame->documentElement(); examineChildElements(document, treeWidget->invisibleRootItem());}//! [begin document inspection]//! [traverse document]void Window::examineChildElements(const QWebElement &parentElement, QTreeWidgetItem *parentItem){ QWebElement element = parentElement.firstChild(); while (!element.isNull()) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0, element.tagName()); parentItem->addChild(item); examineChildElements(element, item); element = element.nextSibling(); }}void Window::getMyPost(QString string){ textEdit->setText(string);}void Window::showPage(QNetworkReply *replay){ if(RecStatus) { QString text; QUrl url = replay->request().url(); text += ">> " + url.toString() + "\n"; QList<QByteArray> rHeaders = replay->request().rawHeaderList(); foreach (QByteArray reqName, rHeaders) { QByteArray reqValue = replay->request().rawHeader(reqName); text += reqName + ": " + reqValue + "\n";; } text += "\n\n"; text += "<< \n"; QList<QByteArray> reqHeaders = replay->rawHeaderList(); foreach (QByteArray reqName, reqHeaders) { QByteArray reqValue = replay->rawHeader(reqName); text += reqName + ": " + reqValue + "\n";; } QByteArray bytes = replay->readAll(); text += "##### "+QString("%1").arg(bytes.length())+ "\n\n"; }}void Window::on_pushButton_clicked(){ webView->page()->setContentEditable(true); QWebElement email = webView->page()->mainFrame()->findFirstElement("input[name=login]"); QWebElement pass = webView->page()->mainFrame()->findFirstElement("input[name=passwd]"); email.setAttribute("value","mylogin"); pass.setAttribute("value","mypass"); QWebElement button = webView->page()->mainFrame()->findFirstElement("input[type=submit]"); if (button.isNull()) QMessageBox::critical(this, "", "error"); button.evaluateJavaScript("this.click();");}void Window::on_pushButton_Rec_clicked(){ RecStatus = true;}void Window::on_pushButton_Pause_clicked(){ RecStatus = false;}