0

尝试从 Azure 语音服务获取令牌时出现以下错误。' https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken 401(拒绝访问)'。
这是我通过 JavaScript 请求令牌的方式: 如果我通过 Windows PowerShell 手动获取令牌,我的机器人工作正常。 什么可能是错的?提前谢谢
const res = await fetch('https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken', { method: 'POST', headers: { Authorization: 'Bearer ' + 'MY_SPEECH_SERVICES_SUBSCRIPTION_KEY'}});
const { authorizationToken } = await res.json();
webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({ authorizationToken, region });


4

1 回答 1

0

分享一种通过javascript获取令牌的方法。“数据”变量将存储令牌。感谢大家的支持!

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

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

        $.ajax({
            url: "https://brazilsouth.api.cognitive.microsoft.com/sts/v1.0/issuetoken" + $.param(params),
            beforeSend: function(xhrObj){
                // Request headers
                xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","MY_SPEECH_SERVICES_SUBSCRIPTION_KEY");
            },
            type: "POST",
            // Request body
            data: "{body}",
        })
        .done(function(data) {
            alert(data);
        })
        .fail(function() {
            alert("error");
        });
    });
</script>
</body>
</html>`
于 2020-03-20T19:20:48.327 回答