curl -k -X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&from=en&to=zh-Hans" -H "Ocp-Apim-Subscription-Key: xxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json; charset=UTF-8" -d "[{'Text':'Hello, what is your name?'}]"
Curl command above works with my subscription key but the equivalent in browser / client javascript below result HTTP 400 error with message as "One of the request inputs is not valid."
$.post({
url: 'https://api.cognitive.microsofttranslator.com/translate?' + jQuery.param({
'api-version': '3.0',
'to': 'zh-Hans'
}),
beforeSend: function (xhr) {
xhr.setRequestHeader("Ocp-Apim-Subscription-Key", "xxxxxxxxxxxxxxxxxxxxx");
},
dataType: 'json',
contentType: 'application/json',
processData: false,
data: [{
'Text': 'Hello, what is your name?'
}],
success: function (data) {
console.info(JSON.stringify(data));
},
error: function (data) {
console.error(JSON.stringify(data));
}