#ifndef MAINWINDOW_H#define MAINWINDOW_H #include <QMainWindow>#include <QtNetwork/QNetworkAccessManager>#include <QUrl>#include <QtNetwork/QNetworkRequest>#include <QtNetwork/QNetworkReply>#include <QDebug> namespace Ui { class MainWindow;} class MainWindow : public QMainWindow{ Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); private: Ui::MainWindow *ui; private slots: void on_pushButton_clicked(); void searshFinished(QNetworkReply*);}; #endif // MAINWINDOW_H
#include "mainwindow.h"#include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this);} MainWindow::~MainWindow(){ delete ui;} void MainWindow::on_pushButton_clicked(){ QNetworkRequest request; request.setUrl(QUrl("http://www.yandex.ru/")); request.setRawHeader("Host", "yandex.ru"); request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; ru; rv:1.9.0.10) Gecko/2009042809 GranParadiso/3.0.10"); //request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)"); //request.setRawHeader("User-Agent", "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.9.168 Version/11.50"); //request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); //request.setRawHeader("Accept-Language", "en-us,en;q=0.5"); //request.setRawHeader("Accept-Encoding", "gzip,deflate"); //request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); request.setRawHeader("Keep-Alive", "115"); request.setRawHeader("Connection", "keep-alive"); //request.setRawHeader("Referer", urlBytes); //request.setRawHeader("Cookie", ""); //request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); //request.setRawHeader("Content-Length", "557"); QNetworkAccessManager* manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)),this, SLOT(searshFinished(QNetworkReply*))); manager->get(request);} void MainWindow::searshFinished(QNetworkReply* reply){ QByteArray ansver = reply->read(reply->bytesAvailable()); qWarning() << ansver;}