Qt 从客户端发起http响应 获取网页数据实现代码
void Test::GetHttp(QString strServerIP,QString strUserName,QString strPasswd) { QNetWorkMananager *manager = new QNetWorkManager(this); connect(manager, SIGNAL(finished(QNetWorkReply *), this, SLOT(OnReplyFinshed(QNetWorkReply*))); QString strUrl; strUrl = QString("http:www.baidu.com"); QNetworkRequest request; requst.setUrl(QUrl(strUrl)); manager->get(request); } void QTest::OnReplyFinshed(QNetworkReply* reply) { //获取响应的信息,状态码为200表示正常 int statusCode = reply->attribut(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if(reply->error() == QNetWorkReply::NoError && statusCode == 200) { QByteArray baData = reply->readAll(); } reply->deleteLater(); }