当前位置: 首页 > news >正文

服务器网站建设情况免费net网站空间

服务器网站建设情况,免费net网站空间,西安做seo的公司,网站备案多少钱1.WinFrom调用webapi接口方法 最近项目要在winfrom项目中调用webAPI#xff0c;故在网上查找资料#xff0c;找到了一个WinFrom调用webapi接口的通用方法#xff0c;关键代码#xff1a; #region WinFrom调用webapi接口通用方法private async Taskstring InvokeWe…1.WinFrom调用webapi接口方法 最近项目要在winfrom项目中调用webAPI故在网上查找资料找到了一个WinFrom调用webapi接口的通用方法关键代码 #region WinFrom调用webapi接口通用方法private async Taskstring InvokeWebapi(string url, string api, string type, Dictionarystring, string dics){string result string.Empty;HttpClient client new HttpClient();client.DefaultRequestHeaders.Add(authorization, Basic YWRtaW46cGFzc3dvcmRAcmljZW50LmNvbQ);//basic编码后授权码client.BaseAddress new Uri(url);client.Timeout TimeSpan.FromSeconds(510);if (type.ToLower() put){HttpResponseMessage response;//包含复杂类型if (dics.Keys.Contains(input)){if (dics ! null){foreach (var item in dics.Keys){api api.Replace(item, dics[item]).Replace({, ).Replace(}, );}}var contents new StringContent(dics[input], Encoding.UTF8, application/json);response client.PutAsync(api, contents).Result;if (response.IsSuccessStatusCode){result await response.Content.ReadAsStringAsync();return result;}return result;}var content new FormUrlEncodedContent(dics);response client.PutAsync(api, content).Result;if (response.IsSuccessStatusCode){result await response.Content.ReadAsStringAsync();return result;}}else if (type.ToLower() post){var content new FormUrlEncodedContent(dics);HttpResponseMessage response client.PostAsync(api, content).Result;if (response.IsSuccessStatusCode){result await response.Content.ReadAsStringAsync();return result;}}else if (type.ToLower() get){HttpResponseMessage response client.GetAsync(api).Result;if (response.IsSuccessStatusCode){result await response.Content.ReadAsStringAsync();return result;}}else{return result;}return result;}#endregion 2.应用实例 创建一个名为callWebAPI的窗体项目在窗体加两个textBox。下面实例主要是调用webAPI的方法获取数据存为json格式然后将json格式的数据从文件中读取出来。调用代码如下 private async void callWebAPI_Load(object sender, EventArgs e){#region 调用webapi并存为json格式文件string api ;string url http://10.3.11.2/SimploWebApi/api/LASER_System/LASER_GetLineShowConfig?typeString2;Dictionarystring, string dics new Dictionarystring, string();Taskstring task InvokeWebapi(url, api, post, dics);string result task.Result;//textBox1.Text result;if (result ! null){JObject jsonObj null;jsonObj JObject.Parse(result);DataInfo info new DataInfo();info.statusCode Convert.ToInt32(jsonObj[statusCode]);//info.message jsonObj[message].ToString();if (info.statusCode 0){JArray jlist JArray.Parse(jsonObj[Data].ToString());string json JsonConvert.SerializeObject(jlist, Formatting.Indented);//File.WriteAllText(Standard.json, json);//将数据存为json格式for (int i 0; i jlist.Count; i) //遍历JArray { JObject tempo JObject.Parse(jlist[i].ToString());textBox1.Text tempo[line].ToString(); }}}#endregion#region 获取json文件数据// 读取JSON文件内容string jsonFilePath Standard.json;string jsons File.ReadAllText(jsonFilePath);// 反序列化JSON到对象Standard standard JsonConvert.DeserializeObjectStandard(jsons);textBox2.Text standard.line , standard.linePlace;#endregion}以上实例还需建立DataInfo类和Standard类 DataInfo类 DataInfo info new DataInfo(); public class DataInfo{public int statusCode { get; set; }public string message { get; set; } } Standard类 Standard standard JsonConvert.DeserializeObjectStandard(jsons); public class Standard{public string line { get; set; }public string linePlace { get; set; } } 以上实例用了json所以需要引用Newtonsoft.Json.dll具体引用方法见以前文章 using Newtonsoft.Json; Standard.json文件 {line: B10,linePlace: CQ_1, } 补充 get的传参方式 string api ;string sWo 1025; string url http://10.1.1.1/api/MES/API_GetLaserAOIParm?sWo sWo ;Dictionarystring, string dics new Dictionarystring, string(); Taskstring task InvokeWebapi(url, api, post, dics);string result task.Result; post的传参方式 string api ;string sWo 1025; string url http://10.1.1.1/api/MES/API_GetLaserAOIParm;Dictionarystring, string dics new Dictionarystring, string();dics new Dictionarystring, string{{ sWo, sWo }, };Taskstring task InvokeWebapi(url, api, post, dics);string result task.Result; 参考文献WinForm如何调用WebApi接口_c# weiapi winform-CSDN博客 结语本文主要记录WinFrom调用webapi接口方法及其应用实例以上代码是本人亲测可用的在此记录方便查阅。
http://www.hkea.cn/news/14413398/

相关文章:

  • 爱站网关键词密度企业微信app下载安装二维码
  • 做一个招聘信息的网站 用什么做网站的软件wordpress是国外服务器吗
  • 郑志平爱站网创始人动漫制作专业可以专升本考什么
  • 苏州网站建设凡科重庆公司建设网站
  • 专门做调查的网站亚马逊品牌网站怎么做
  • 做ppt音乐模板下载网站产品线上推广方案
  • 小程序网站建设制作集团网站下分网站 模板
  • 有源码帮忙搭建网站吗wordpress写博客流行吗
  • 优化网站推广高校网站建设要点
  • 郎溪网站建设h5页面怎么生成链接
  • 济南网站建设与优化青岛市房产信息网官网
  • 国际金融资讯做的好的网站福州网站建设
  • 设计商城的网站建设网站的视频
  • 联合网站设计彩票系统网站开发
  • php网站备份网络推广工作内容
  • 网站文案设计行业外贸网站建设
  • 贸易做网站产品设计优秀网站
  • 网站开发不让搜索引擎展示型网站制作服务
  • 教你做面膜v官方网站天辰建设信息网
  • 网站建设职位名称wordpress WP-Wiki
  • 温州建设集团有限公司网站首页wordpress python代码
  • 为什么博客需要wordpress湖南seo技术培训
  • 信阳市网站建设夏津网站建设
  • 网站优化标题建设库官网查询系统
  • 怎么做 在线电影网站南宁市网站设计
  • 贵阳网站建设企业企业解决方案网站
  • 做挖机配件销售的网站网站建设所需美工
  • 一个网络空间做两个网站营业推广名词解释
  • 做医院的网站 配色怎么选择如何做阿里巴巴的网站
  • 怎样建立俄罗斯网站大兴网站建设费用