Qt Http get
1、直接建立连接,向网站发送http请求
QNetworkAccessManager *accessManager = new QNetworkAccessManager(this); connect(accessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); accessManager->get(QNetworkRequest(QUrl("http:xxxxx")));
2、在槽函数中打印【注意:如果返回字节数过大,qDebug是打印不出来的,可通过size查看返回字节数】
void MainWindow::replyFinished(QNetworkReply *reply) { if (reply->error() == QNetworkReply::NoError) { QByteArray bytes = reply->readAll(); qDebug() << bytes; } else { qDebug() << "finishedSlot errors here"; qDebug( "found error .... code: %d\n", (int)reply->error()); qDebug(qPrintable(reply->errorString())); } }
长风破浪会有时,直挂云帆济沧海!
可通过下方链接找到博主
https://www.cnblogs.com/judes/p/10875138.html