用于文本分析的Javascript调用返回HTTP 400错误请求错误

用于文本分析的Javascript调用返回HTTP 400错误请求错误,javascript,microsoft-cognitive,Javascript,Microsoft Cognitive,对于使用Javascript的文本分析400错误请求错误问题,我找不到类似的问题。下面Javascript中的简单代码返回了一个错误。我已经核实了发送的邮件是有效的。我需要你的帮助 var params = { "documents": [ { "language": "en", "id": "1", "text": "This is my first test. All is good"

对于使用Javascript的文本分析400错误请求错误问题,我找不到类似的问题。下面Javascript中的简单代码返回了一个错误。我已经核实了发送的邮件是有效的。我需要你的帮助

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");
});
@雷兹, 请参阅此提琴以了解实现。只需在“此处为您的钥匙”处更换钥匙即可:

以下是成功运行的代码:

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({
                 method: 'POST',
                url: "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment",
                headers:{
                    "Content-Type":"application/json",
                  "Ocp-Apim-Subscription-Key":"YOUR_KEY_HERE",
                  "Accept":"application/json"
                },
                data: JSON.stringify(params),
                dataType: 'text',
            })
            .done(function(data) {
                console.log('Here: ' + data);
                $('#responseData').html(data);
            })
            .fail(function(data) {
                alert("error" + JSON.stringify(data));
            });

祝你好运。希望您能了解它的运行情况。

看起来这个api总是返回404?