Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6002759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:01:29+00:00 2026-05-23T01:01:29+00:00

I’m trying to use Microsoft’s Translator API in my Rails app. Unfortunately and mostly

  • 0

I’m trying to use Microsoft’s Translator API in my Rails app. Unfortunately and mostly unexpected, the server answers always with an internal server error. I also tried it manually with Poster[1] and I get the same results.

In more detail, what am I doing? I’m creating an XML string which goes into the body of the request. I used the C# Example of the API documentation. Well, and then I’m just invoking the RESTservice.
My code looks like this:

xmlns1 = "http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2"
xmlns2 = "http://schemas.microsoft.com/2003/10/Serialization/Arrays"

xml_builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
  xml.TranslateArrayRequest("xmlns:ms" => xmlns1, "xmlns:arr" => xmlns2) {
     xml.AppId token  #using temporary token instead of appId
     xml.From  source
     xml.To    target

     xml.Options {
       xml["ms"].ContentType {
         xml.text "text/html"
       }
     }

     xml.Texts {
       translate.each do |key,val|
          xml["arr"].string {
            xml.text CGI::unescape(val)
          }
       end
     }
   }
end

headers = {
   'Content-Type' => 'text/xml'
}

uri = URI.parse(@@msTranslatorBase + "/TranslateArray" + "?appId=" + token) 
req = Net::HTTP::Post.new(uri.path, headers)
req.body = xml_builder.to_xml

response = Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
# [...]

The xml_builder produces something like the following XML. Differently to the example from the API page, I’m defining two namespaces instead of referencing them on the certain tags (mainly because I wanted to reduces the overhead) — but this doesn’t seem to be a problem, when I do it like the docu-example I also get an internal server error.

<?xml version="1.0" encoding="UTF-8"?>
<TranslateArrayRequest xmlns:ms="http://schemas.datacontract.org/2004/07/Microsoft.MT.Web.Service.V2" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
  <AppId>TX83NVx0MmIxxCzHjPwo2_HgYN7lmWIBqyjruYm7YzCpwnkZL5wtS5oucxqlEFKw9</AppId>
  <From>de</From>
  <To>en</To>
  <Options>
    <ms:ContentType>text/html</ms:ContentType>
  </Options>
  <Texts>
    <arr:string>Bitte übersetze diesen Text.</arr:string>
    <arr:string>Das hier muss auch noch übersetzt werden.</arr:string>
  </Texts>
</TranslateArrayRequest>

Every time I request the service it answers with

#<Net::HTTPInternalServerError 500 The server encountered an error processing the request. Please see the server logs for more details.>

… except I do some unspecified things, like using GET instead of POST, then it answers with something like “method not allowed”.

I thought it might be something wrong with the XML stuff, because I can request an AppIdToken and invoke the Translate method without problems. But to me, the XML looks just fine. The documentation states that there is a schema for the expected XML:

The request body is a xml string generated according to the schema specified at http:// api.microsofttranslator.com/v2/Http.svc/help

Unfortunately, I cannot find anything on that.

So now my question(s): Am I doing something wrong? Maybe someone experienced similar situations and can report on solutions or work-arounds?


[1] Poster FF plugin > addons.mozilla.org/en-US/firefox/addon/poster/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:01:30+00:00Added an answer on May 23, 2026 at 1:01 am

    Well, after lot’s of trial-and-error I think I made it. So in case someone has similar problems, here is how I fixed this:

    Apparently, the API is kind of fussy with the incoming XML. But since there is no schema (or at least I couldn’t find the one specified in the documentation) it’s kind of hard to do it the right way: the ordering of the tags is crucial!

    <TranslateArrayRequest>
      <AppId/>
      <From/>
      <Options />
      <Texts/>
      <To/>
    </TranslateArrayRequest>
    

    When the XML has this ordering it works. Otherwise you’ll only see the useless internal server error response. Furthermore, I read a couple of times that the API also breaks if the XML contains improper UTF-8. One can force untrusted UTF-8 (e.g. coming from a user form) this way:

    ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
    valid_string = ic.iconv(untrusted_string + ' ')[0..-2]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.