问题描述
团队,
我正尝试使用该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);
出现以下错误
对此表示感谢,
推荐答案
您可以参考此博客,以解决调用API时接收未经授权的错误(401)"的问题.
You may refer to thisblog for troubleshooting on "Receiving unauthorized errors (401) while invoking APIs".
类似的问题已在,请尝试遵循建议的解决方法,看看是否有帮助.
Similar issue has been discussed inMSDN 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时出现授权错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!