Qt发送HTTP请求
2021-06-28 03:05
标签:sign network else byte setup let ini cpp out mainwindow.h mainwindow.cpp Qt发送HTTP请求 标签:sign network else byte setup let ini cpp out 原文地址:http://www.cnblogs.com/coolbear/p/7144856.html#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scanTimer = new QTimer(this);
//connect( scanTimer, &QTimer::timeout, this, &MainWindow::scanURLIsOK );
scanTimer->start( 1000*5 ); // for 100fps
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::scanURLIsOK()
{
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkRequest request;
// 发送https请求前准备工作;
QSslConfiguration config;
QSslConfiguration conf = request.sslConfiguration();
conf.setPeerVerifyMode(QSslSocket::VerifyNone);
conf.setProtocol(QSsl::TlsV1SslV3);
request.setSslConfiguration(conf);
//request.setUrl(QUrl("http://www.urlshare.cn/umirror_url_check?url=http://www.fgggg.com"));
request.setUrl(QUrl("http://www.hugedomains.com"));
QNetworkReply* reply = manager->get(request);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinish(QNetworkReply*)));
}
void MainWindow::replyFinish(QNetworkReply *reply)
{
if(reply && reply->error() == QNetworkReply::NoError) {
QByteArray data = reply->readAll();
int len = data.size();
QString s=QString::fromStdString(data.toStdString());
qDebug() s;
} else {
qDebug() errorString();
}
reply->close();
}
void MainWindow::on_pushButton_clicked()
{
scanURLIsOK();
}