我正在尝试构建一个应使用Microsoft Azure Cognitve Services Emotion API的Web应用程序。
我使用JavaScript(jQuery)将AJAX请求发送到分配的端点服务器。
这是我的尝试:

<!DOCTYPE html>
<html>
<head>
    <title>JSSample</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>

<h2>Face Rectangle</h2>
<ul id="faceRectangle">
</ul>

<h2>Emotions</h2>
<ul id="scores">
</ul>

<body>

<script type="text/javascript">
    $(function() {
        var params = { };

        $.ajax({
            url: "https://westus.api.cognitive.microsoft.com/emotion/v1.0?" + $.param(params),
            beforeSend: function(xhrObj){

                xhrObj.setRequestHeader("Content-Type","application/json");

                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","<key>");
            },
            type: "POST",
            data: '{"url": "<some picture's URL>"}',
        }).done(function(data) {
            var faceRectangle = data[0].faceRectangle;
            var faceRectangleList = $('#faceRectangle');

            for (var prop in faceRectangle) {
                faceRectangleList.append("<li> " + prop + ": " + faceRectangle[prop] + "</li>");
            }

            var scores = data[0].scores;
            var scoresList = $('#scores');

            for(var prop in scores) {
                scoresList.append("<li> " + prop + ": " + scores[prop] + "</li>")
            }
        }).fail(function(err) {
            alert("Error: " + JSON.stringify(err));
        });
    });
</script>
</body>
</html>


来自服务器的确切错误响应是:


  错误:{“ readyState”:4,“ responseText”:“ {\” error \“:{\” code \“:\” ResourceNotFound \“,\” message \“:\”找不到资源。\“}} “,”状态“:404,”状态文本“:”找不到资源“}


服务器显然无法回答我的请求。有人可以解释服务器的错误响应还是看到我的代码中的缺陷?

最佳答案

基于the official documentation,Emotion API的请求URL应为:

https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognize

关于javascript - Azure的Cognitive Services Emotion API返回404,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48510581/

10-09 06:25