In Translation services using Bing API I posted a method for calling Microsoft's translation API. I have an alternative piece of code that accomplishes the same thing.
Here is the code I posted in the Translate function:
xml.Open "GET", _ "http://api.microsofttranslator.com/V2/Http.svc/Translate?appID=" & _ appID & "&text=" & textToTranslate & "&from=" & fromLang & "&to=" & _ toLang, False xml.Send
This code uses a GET request, and as such, all the required parameters must be stuffed into the final URL.
But we can also make a POST request and make things a bit cleaner. First we declare the Bing URL and app IDs as a constant:
Const BING_URL As String = _ "http://api.microsofttranslator.com/V1/Http.svc/Translate" Const BING_APPID As String = "your app ID here"
Then we can make our POST request like this:
With xml .Open "POST", BING_URL & "?appId=" & BING_APPID & "&from=" & _ fromLang "&to=" & toLang .setRequestHeader "Content-Type", "text/plain" .Send textToTranslate End With
Follow Me