尝试从控制台应用程序访问Azure API管理API时出现授权错误 [英] Authorization error when trying to access Azure API Management API From console application

查看:81
本文介绍了尝试从控制台应用程序访问Azure API管理API时出现授权错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

团队,

我正尝试使用该API,该API是通过API Management API URL在Azure中托管的应用程序服务.我可以通过开发门户和API管理控制台成功进行通信.

I was trying to consume the API, which is an App Service hosted in Azure through the API Management API URL. I am able to successfully make the communication thought the Dev Portal And API Management Console.

我确实复制并粘贴了开发人员门户中可用的代码.

I did copy paste the code available in the Developer Portal.

            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            //请求标头
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key","{profile的密钥}");
            var uri ="http://mornt.azure-api.net/car/api/Car";
            HttpResponseMessage响应;
           响应=等待client.GetAsync(uri);
            Console.WriteLine(response);

            var client = new HttpClient();
            var queryString = HttpUtility.ParseQueryString(string.Empty);

            // Request headers
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "{key from profile}");
            var uri = "http://mornt.azure-api.net/car/api/Car";
            HttpResponseMessage response;
            response = await client.GetAsync(uri);
            Console.WriteLine(response); 

出现以下错误

对此表示感谢,

推荐答案

如果您使用无效的订阅密钥进行访问,通常会出现401错误API.

401 error usually occurs, if you are using an invalid subscription key to access API.

博客,以解决调用API时接收未经授权的错误(401)"的问题.

You may refer to this blog for troubleshooting on "Receiving unauthorized errors (401) while invoking APIs".

MSDN线程,请尝试遵循建议的解决方法,看看是否有帮助.

Similar issue has been discussed in MSDN thread, try to follow the suggested workaround and see if it helps.

如果此答案有帮助,请单击标记为答案"或投票.为了在您的论坛上提供其他反馈 体验,请单击

If this answer was helpful, click "Mark as Answer" or Up-Vote. To provide additional feedback on your forum experience, click here


这篇关于尝试从控制台应用程序访问Azure API管理API时出现授权错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆