Hello, I'm trying to use the REST API to get a list of targets, but the rest method returns an "Host requires authentication". I'm using the QT framework to develop a c++ applications.
Here is the code, I post only the relevant part (secretKey and accessKey aren't listed). It's only a test to see if everything works, so the code is far from perfect or optimized.
QString baseURL = "https://vws.vuforia.com"; QString signature; QString method = "GET"; QString hexDigest = "d41d8cd98f00b204e9800998ecf8427e"; QString contentyType = ""; QNetworkAccessManager *manager = new QNetworkAccessManager(this); QNetworkRequest request(QUrl(baseURL + "/targets")); QString dateTime = dateString(QDateTime::currentDateTimeUtc()); request.setRawHeader("Date", dateTime.toLocal8Bit()); QByteArray dateBA = dateTime.toLatin1(); // get the /targets string QString requestPath = "/" + request.url().fileName() + "/"; signature = method + "\n" + hexDigest + "\n" + contentyType + "\n" + QString(dateBA) + "\n" + requestPath; qDebug() << signature.toLocal8Bit(); QByteArray signatureBA = QMessageAuthenticationCode::hash( QByteArray(signature.toLocal8Bit()), QByteArray(secretKey.toLocal8Bit()), QCryptographicHash::Sha1) .toBase64(); request.setRawHeader(QByteArray("Authorization"), QString("VWS " + accessKey + ":" + signatureBA).toLatin1() ); connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(slotRequestFinished(QNetworkReply *))); connect(manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), SLOT(authentication(QNetworkReply*,QAuthenticator*))); QNetworkReply *reply = manager->get(request);
QNetworkManager is the class that handles the GET request
; the following callback handles the response
if (reply->error() > 0) { qDebug() << "ERROR -> " << reply->errorString(); } else { //QString replyString = QString(reply->readAll()); QByteArray bytes = reply->readAll(); QString str = QString::fromUtf8(bytes.data(), bytes.size()); int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); }
The reply->errorString is "Host requires authentication" and the status code is 204. The Qt documentation says:
"the remote server requires authentication to serve the content but the credentials provided were not accepted (if any)"
If I replace the url https://vws.vuforia.com with another https url, for example https://www.google.com, I correctly receive the content.
How can I supply the credentials ?Thank you.Mario