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

做游戏交易网站有哪些淘宝的前100个关键词排名

做游戏交易网站有哪些,淘宝的前100个关键词排名,商城平台开发公司,网站自动采集rss场景 Winform中怎样使用HttpClient调用http的get和post接口并将接口返回json数据解析为实体类: Winform中怎样使用HttpClient调用http的get和post接口并将接口返回json数据解析为实体类_winform解析json-CSDN博客 上面使用HttpClient调用post接口时使用的HttpCon…

场景

Winform中怎样使用HttpClient调用http的get和post接口并将接口返回json数据解析为实体类:

Winform中怎样使用HttpClient调用http的get和post接口并将接口返回json数据解析为实体类_winform解析json-CSDN博客

上面使用HttpClient调用post接口时使用的HttpContent的格式为 application/x-www-form-urlencoded

对应的代码实现

                var body = new FormUrlEncodedContent(new Dictionary<string, string>{{"serverName", "zlw"},{"mineCode", this.textBox_mineCode.Text.Trim().ToString()},{"targetServer",this.textBox_targetServer.Text.Trim().ToString()},{"port", this.textBox_port.Text.Trim().ToString()},{"user", this.textBox_user.Text.Trim().ToString()},{"pass", this.textBox_pass.Text.Trim().ToString()},{"dir", this.textBox_dir.Text.Trim().ToString()},{"filePath", this.textBox_filePath.Text.Trim().ToString()},});// responsevar response = httpClient.PostAsync(url, body).Result;

如果调用接口时明确指出必须是application/json格式,则需要修改代码实现方式。

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi 

实现

1、以调用若依框架的登录接口为例,需要传递application/json的用户名和密码参数

这里为快速实现,所以手动构造和转义json字符串

var jsonContent = "{\"username\":\"bGVk\",\"password\":\"MTIzNDU2Nzg=\"}";

实际使用时需要使用正规的json序列化工具等方式。

然后content不再是FormUrlEncodedContent,而是StringContent

var content = new StringContent(jsonContent, Encoding.UTF8, "application/json")

然后传参时

var response = httpClient.PostAsync(url, content).Result;

2、完整示例代码

​var httpClient = new HttpClient();var url = new Uri("http://127.0.0.1:192/prod-api/login");var jsonContent = "{\"username\":\"bGVk\",\"password\":\"MTIzNDU2Nzg=\"}";using (var content = new StringContent(jsonContent, Encoding.UTF8, "application/json")){var response = httpClient.PostAsync(url, content).Result;if (response.IsSuccessStatusCode){var responseContent = response.Content.ReadAsStringAsync();var data = responseContent.Result;Console.WriteLine(data);JavaScriptSerializer js = new JavaScriptSerializer();//实例化一个能够序列化数据的类LoginResult result = js.Deserialize<LoginResult>(data);Console.WriteLine(result.token);}} ​

后面的部分则是读取返回值并序列化为实体类

其中实体类LoginResult为

    class LoginResult{/// <summary>/// 操作成功/// </summary>public string msg { get; set; }/// <summary>////// </summary>public int code { get; set; }/// <summary>////// </summary>public string token { get; set; }}

测试结果

http://www.khdw.cn/news/54528.html

相关文章:

  • 搭建网站需要多少钱东莞最新消息今天
  • 网站建设销售实习报告做网站企业
  • 北京中心网站建设免费企业黄页查询官网
  • 哪个网站可以做批发玻璃胶搜索指数的数据来源是什么
  • 广州做网站怎么样郴州网络推广外包公司
  • 国外包装设计网站班级优化大师使用指南
  • 网站专题页面怎么做什么是白帽seo
  • ssl 加密网站推广运营
  • ps模板下载网站seo优化诊断工具
  • 物价局网站建设情况汇报重庆seo团队
  • 建企业网站浩森宇特刚刚突发1惊天大事
  • 群晖做网站服务器会卡吗百度极简网址
  • 网站详情页用哪个软件做it学校培训学校哪个好
  • 网站建设公司的公司哪家好seo查询系统
  • 织梦网站tel标签app推广方案范例
  • 福建网站建设模板百度6大核心部门
  • 江苏有什么网站找工程建设人员介绍网络营销的短文
  • 企业cms建站会计培训机构
  • html5做网站链接电工培训技术学校
  • 为什么建手机网站设计公司排名
  • 怎么在记事本上做网站奉节县关键词seo排名优化
  • 网站被挂黑链怎么办营销型网站的分类不包含
  • 做网站图片太大好吗seo外包公司费用
  • 网站推广 网站yahoo搜索引擎入口
  • 微信做淘宝客网站百度统计工具
  • 网站核验单下载百度资讯指数
  • 静态网页模板免费网站世界羽联最新排名
  • 云开发网站贵阳网站建设制作
  • 租号网站怎么做的百度热词指数
  • 连云港网站关键字优化市场写软文的平台有哪些