0
我無法爲Text Analytics 400錯誤的請求使用Javascript找到類似的問題。以下JavaScript中簡單的代碼返回了一個錯誤。我已驗證發送的POST是否有效。我需要你的幫助。Javascript調用文本分析返回HTTP 400錯誤請求錯誤
var params = {
"documents": [
{
"language": "en",
"id": "1",
"text": "This is my first test. All is good"
},
{
"language": "en",
"id": "2",
"text": "This is my first test. All is not good"
},
{
"language": "en",
"id": "3",
"text": "Why is this not working as expected?"
},
{
"language": "en",
"id": "4",
"text": "You got to be kidding me like this"
},
{
"language": "en",
"id": "5",
"text": "I hope this will finally work. I hope it will"
}
]
}
$.ajax({
url: "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","MY API KEY");
},
type: "POST",
// Request body
data: "{body}",
})
.done(function(data) {
console.log(data);
})
.fail(function() {
alert("error");
});
看起來像這樣的api總是返回一個404. https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment? – Vincent