本帖最后由 海军 于 2021-1-5 09:42 编辑
[C++] 纯文本查看 复制代码 QString url = "https://www.baidu.com/s?ie=utf-8&wd=";
url.append(keyword);
QNetworkRequest request;
QNetworkAccessManager* naManager = new QNetworkAccessManager(this);
QMetaObject::Connection connRet = QObject::connect(naManager,
SIGNAL(finished(QNetworkReply*)),
this, SLOT(requestFinished(QNetworkReply*)));
request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36");
request.setRawHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
request.setRawHeader("Host","www.baidu.com");
request.setRawHeader("Connection","keep-alive");
request.setRawHeader("Upgrade-Insecure-Requests","1");
request.setRawHeader("Accept-Encoding","deflate");
QSslConfiguration config;
config.setPeerVerifyMode(QSslSocket::VerifyNone);
config.setProtocol(QSsl::TlsV1_2);
request.setSslConfiguration(config);
request.setUrl(QUrl(url));
QNetworkReply *reply = naManager->get(request);
reply->ignoreSslErrors();
[C++] 纯文本查看 复制代码 void Widget::requestFinished(QNetworkReply* reply){
int httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qWarning() << httpStatus<<endl;
qWarning() << reply->readAll();
} |