azure 问题令牌 api 由于缺少订阅密钥而返回访问被拒绝

Maz*_*lih 1 javascript azure azure-api-management

我正在尝试调用 bing 文本转语音 azure 服务,但在获取访问令牌时我不断收到此错误,尽管提供了订阅密钥

function requestAudio(text,lang)
{
    nameLanguage = "Microsoft Server Speech Text to Speech Voice (en-GB, Susan, Apollo)";
    language = lang;
    textToSpeak = text;
    $.ajax(
    {
        type: 'POST',
        url: tokenURL,
        data: 
        {  
            'Ocp-Apim-Subscription-Key': 'xxxxxxf8cc34d08b646de1bc54c950d'
        }
    }).done(function(data) 
    { 
        token = data.access_token;
        sendAudioRequest();
    });
}
Run Code Online (Sandbox Code Playgroud)

来自 fiddler 的错误是

{ "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API." }
Run Code Online (Sandbox Code Playgroud)

我打电话的网址是

https://api.cognitive.microsoft.com/sts/v1.0/issueToken
Run Code Online (Sandbox Code Playgroud)

4c7*_*b41 5

我很确定你必须在标题中设置它们,而不是在正文中。

beforeSend: function(request) {
  request.setRequestHeader("Ocp-Apim-Subscription-Key", 'xxxxxxf8cc34d08b646de1bc54c950d');
},
Run Code Online (Sandbox Code Playgroud)

参考:https://msdn.microsoft.com/en-us/library/mt712546.aspx