0
votes

I am trying to writing a Qt based REST client that will communicate with Microsoft Cognitive Token Service using my Subscription-Key and get an authentication token which later I can use for establishing connection with Microsoft Cognitive Services API.

Authentication Token API documentation: http://docs.microsofttranslator.com/oauth-token.html

The following is my code:

QByteArray jsonString = "{\"Ocp-Apim-Subscription-Key\":\"***********************"}";
QUrl serviceURL("https://api.cognitive.microsoft.com/sts/v1.0/issueToken");
QNetworkRequest request(serviceURL);
request.setRawHeader("Content-Type", "application/json")
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkReply *reply = manager->post(request, jsonString);
qDebug() << reply->errorString();

Error:

unknown error

The above code always returns unknown error. I would appreciate someone point me in the right direction for fixing this problem.

Thank you.

2
What is the error (text) you are getting? - Ronak
@Ronak error -> unknown error - sanjayan ravi

2 Answers

1
votes

Check carefully the present of backslash before the all double quotes in jsonString.

0
votes

Refer to the Microsoft Translator API documentation at http://docs.microsofttranslator.com

You can also choose to bypass getting a token and use the API key in the call. In your http request to api.microsofttranslator.com or dev.microsofttranslator.com, set the http header "Ocp-Apim-Subscription-Key" to your subscription key.

Do not make a call to the token service (https://api.cognitive.microsoft.com/sts/v1.0/issueToken)

Do not use the AppID parameter or the "Authorization" http header.

The documentation noted above is updated accordingly.

A C# example is here: https://github.com/MicrosoftTranslator/TranslateWithAzureSubscriptionKeyAuthentication