#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QPushButton>#include <QUrl>#include <QtNetwork>#include <QDebug>class mainWindow: public QMainWindow{ Q_OBJECTpublic: mainWindow();private: QPushButton *btn;private slots: void searshFinished(QNetworkReply*); void sendRequest();};#endif // MAINWINDOW_H
#include <mainWindow.h>mainWindow::mainWindow(){ btn = new QPushButton("go", this); connect(btn, SIGNAL(clicked()),this, SLOT(sendRequest()));}void mainWindow::sendRequest(){ QNetworkAccessManager *manager = new QNetworkAccessManager(this); manager->get(QNetworkRequest(QUrl("http://www.youtube.com/"))); connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(searshFinished(QNetworkReply*)));}void mainWindow::searshFinished(QNetworkReply* networkReply){ if (!networkReply->error()) { QString data = QString::fromUtf8(networkReply->readAll()); qDebug() << data; }else qDebug() << "error";}
C++ (Qt) QNetworkRequest request(url); request.setRawHeader("Host", "XXX.uz.gov.ua"); request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0"); request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); request.setRawHeader("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3"); request.setRawHeader("Accept-Encoding", "deflate"); request.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); request.setRawHeader("Referer", "http://XXXXX.uz.gov.ua/ru/"); request.setRawHeader("Connection", "keep-alive"); request.setRawHeader("Pragma", "no-cache"); request.setRawHeader("Content-Length", "0"); QNetworkReply* reply = accessManager_->get(request); connect(reply, SIGNAL(finished()), this, SLOT(finishLoadCities()));