Log in or register to post comments

Host requires authentication

May 14, 2015 - 7:57am #1

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 =
    request.setRawHeader(QByteArray("Authorization"), QString("VWS " + accessKey + ":" + signatureBA).toLatin1()  );
    connect(manager, SIGNAL(finished(QNetworkReply*)),
            SLOT(slotRequestFinished(QNetworkReply *)));
    connect(manager, SIGNAL(authenticationRequired(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.


Host requires authentication

May 18, 2015 - 5:36pm #2

I would suggest using the Java VWS samples we provide as a reference. You can debug and step through the sample code to see how the request is setup.



Log in or register to post comments