REST API 调用 方法
METHOD DESCRIPTION
GET Retrieves the specified resource
POST Creates a resource
PATCH Updates the specified resource
DELETE Deletes the specified resource
HEAD Similar to get except only returns HTTP headers
示例
https://docs.microsoft.com/en-us/IIS-Administration/api/crud
代码示例RestSharp
01
02
03
04
05
06
07
08
09
|
var client = new RestClient(iisAdminBaseUrl); ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true ; var request = new RestRequest( "/api/webserver/websites" , Method.GET); request.AddHeader( "Access-Token" , $ "Bearer {token}" ); request.AddHeader( "Accept" , "application/hal+json" ); IRestResponse response = client.Execute(request); if (response.IsSuccessful) { …… } |
代码示例HttpClient
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
|
var apiClient = new HttpClient( new HttpClientHandler() { UseDefaultCredentials = true , ServerCertificateCustomValidationCallback = (message, cert, chain, error) => true }, true ); // Set access token for every request apiClient.DefaultRequestHeaders.Add( "Access-Token" , "Bearer {token}" ); // Request HAL (_links) apiClient.DefaultRequestHeaders.Add( "Accept" , "application/hal+json" ); var res = await apiClient.GetAsync( "https://localhost:55539/api/webserver/websites" ); if (res.StatusCode != HttpStatusCode.OK) { HandleError(res); return ; } JArray sites = JObject.Parse(res.Content.ReadAsStringAsync().Result).Value<JArray>( "websites" ); |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步