Search code examples
apiazuretranslatebing

Microsoft Translator Text API doesn't work


I want to use Microsoft Translator API but I am unable to use it.

I created a Microsoft Azure account as specified in the documentation (http://docs.microsofttranslator.com/text-translate.html) and I created a resource.

When I call the web service to get an access toke, every time I get an exception because a time out..

This is my code (it's Apex, similar to Java) :

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setHeader('Content-Length', '3495');
req.setEndpoint('https://api.cognitive.microsoft.com/sts/v1.0/issueToken?Subscription-Key=[myAPIKey]');
req.setTimeout(20000);
HttpResponse res = h.send(req);

If I remove my API key or I the content length from the header, I get an error from Microsoft.

Do you know why I get this?

Thanks


Solution

  • It works fin now.

    I edit my code and it is ok :

    HttpRequest req = new HttpRequest();
    req.setMethod('GET');
    req.setEndpoint(theURL);
    req.setHeader('Content-Type','application/xml');
    Http binding = new Http();
    HttpResponse res = binding.send(req);
    

    Thanks