Bing Translation API Update

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
About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »



Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

This article is closed to any future comments.
Random Data Generator