How could I call Azure Maps API in C# with authorisation and client id?

大城市里の小女人 提交于 2019-12-24 03:24:03

问题


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.

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…..

回答1:


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

Don't forget to start by installing the RestSharp NuGet package.




回答2:


There is an open source project that provides a .NET client for the Azure Maps REST services. There is a NuGet package too. You can find it here: https://github.com/perfahlen/AzureMapsRestServices The Azure Maps plans on also providing an official .NET client for the rest services later this year.



来源:https://stackoverflow.com/questions/55367075/how-could-i-call-azure-maps-api-in-c-sharp-with-authorisation-and-client-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!