Authorization or any other header can be added to QNetworkRequest or QHttpRequestHeader objects. Below small code example how to add the Authorization header to QNetworkRequest and post the request via QNetworkAccessManager.
Code:
void HTTPService::doPost(QString url, QString userName, QString password, QString data)
{
QString credentials = userName + ":" + password;
credentials = "Basic " + credentials.toAscii().toBase64();
QUrl qurl(url);
QNetworkRequest request(qurl);
request.setRawHeader(QByteArray("Authorization"),credentials.toAscii());
//m_nManager is QNetworkAccessManager object
//currentDownload is ptr to QNetworkReply
m_currentDownload = m_nManager.post(request,"data=" + QUrl::toPercentEncoding(data));
//pageReady function gets called when HTTP request is completed
connect(m_currentDownload, SIGNAL(finished()),SLOT(pageReady()));
}
As said earlier another option is to use QHttpHeader and QHttp classes.