如何使用授权和客户端ID在C#中调用Azure Maps API? [英] How could I call Azure Maps API in C# with authorisation and client id?
本文介绍了如何使用授权和客户端ID在C#中调用Azure Maps API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 Azure Maps API 通过其坐标搜索点周围的POI,但我不知道如何通过添加 Authorization 和 client-id .
I am trying to use Azure Maps API to search POIs around a point using its coordinates, and I do not know how to call the API by adding the Authorization and client-id.
这是我在Microsoft文档网站上尝试API时收到的请求预览.
This is the request preview I get when I try the API on the Microsoft documentation website.
GET https://atlas.microsoft.com/search/poi/json?api-version=1.0&query=university&lat=10.8232&lon=2.98234&limit=1
Authorization: Bearer eyJ0eXAiOiJKV1……
X-ms-client-id: SUXrtewLVItIG3X5…..
推荐答案
您可以使用RestSharp.授权和客户端ID添加为标头:
You could use RestSharp. The authorization and client-id are added as header:
using RestSharp;
string url = $"https://atlas.microsoft.com/search/poi/json?api-version=1.0&query=university&lat=10.8232&lon=2.98234&limit=1";
var client = new RestClient(url);
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Authorization", "Bearer eyJ0eXAiOiJKV1……");
request.AddHeader("X-ms-client-id", "SUXrtewLVItIG3X5…..");
IRestResponse response = client.Execute(request);
if (response.IsSuccessful)
{
string content = response.Content;
}
别忘了开始安装RestSharp NuGet软件包.
Don't forget to start by installing the RestSharp NuGet package.
这篇关于如何使用授权和客户端ID在C#中调用Azure Maps API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文