azure issue token api返回由于缺少订阅密钥而拒绝访问

时间:2017-02-26 11:29:22

标签: javascript azure azure-api-management

我正在尝试将bing文本称为语音天文服务,但我在获取访问令牌时仍然遇到此错误,尽管提供了订阅密钥

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();
    });
}

完全来自fiddler的错误是

{ "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API." }

我正在拨打的网址是

https://api.cognitive.microsoft.com/sts/v1.0/issueToken

1 个答案:

答案 0 :(得分:2)

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

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

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