1. 程式人生 > >QNetworkAccessManager之http非同步請求

QNetworkAccessManager之http非同步請求

QByteArray HttpUtil::getData(QNetworkRequest request /*= QNetworkRequest()*/, const QByteArray & data /*= QByteArray()*/)
{
	m_networkReply = m_networkAccessManager->get(request);
	connect(m_networkReply, &QIODevice::readyRead, this, &HttpUtil::onReadyRead);
	connect(m_networkReply, &QIODevice::finished, this, &HttpUtil::onFinished);
	return QByteArray();
}


void HttpUtil::onReadyRead()
{
	QByteArray byteArray;

	byteArray = m_networkReply->readAll();

	qDebug() << "byteArray###:" << QString::fromUtf8(byteArray);
}