关于使用插件访问接口
.Net 版本: NET Framework 4.7.2
RestSharp版本:105.2.3.0
-
Post访问
static string PostAction() { //公共api const string url = "https://api.uomg.com/api/rand.qinghua"; //添加api访问路径 var clientSpot = new RestClient(url); var requestSpot = new RestRequest(Method.POST); requestSpot.AddHeader("Content-Type", "application/json"); requestSpot.AddQueryParameter("format", "json"); var responseSpot = clientSpot.Execute(requestSpot); if (responseSpot.StatusCode != HttpStatusCode.OK) { return "访问接口出错"; } else { var resultObj = JsonConvert.DeserializeObject<ResultDto>(responseSpot.Content); return resultObj.content; } }
-
Get访问
static string GetAction() { //公共api const string url = "https://api.uomg.com/api/rand.qinghua"; //添加api访问路径 var clientSpot = new RestClient(url); var requestSpot = new RestRequest(Method.GET); requestSpot.AddHeader("Content-Type", "application/json"); requestSpot.AddQueryParameter("format", "json"); var responseSpot = clientSpot.Execute(requestSpot); if (responseSpot.StatusCode != HttpStatusCode.OK) { return "访问接口出错"; } else { var resultObj = JsonConvert.DeserializeObject<dynamic>(responseSpot.Content); return resultObj.content; } }
其他请求方式未找到对应免费API接口
标签:responseSpot,插件,requestSpot,C#,接口,访问,api,var From: https://www.cnblogs.com/hanyiblog/p/17509380.html