zoukankan      html  css  js  c++  java
  • WebClient 请求返回的是Gbk编码解决方案

    WebClient client = new WebClient();
                    client.Headers.Clear();
                    client.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
                    client.Encoding = Encoding.GetEncoding("gbk");
                    string data = "&userCode = " + this.Property.userCode + " & userPwd = " + this.Property.userPwd + "&date=" + t.ToString("yyyy-MM-dd") +"&ifSearched="+this.Property.IfSearched;
                    byte[] b = client.UploadData(this.Property.callUrl, "post", Encoding.GetEncoding("gbk").GetBytes(data));
                    //var resultXml = this.Post(this.Property.callUrl,new {
                    string resultXml= System.Text.Encoding.GetEncoding("gbk").GetString(b);
                    this.LogInfo("上行返回:" + resultXml);
                    resultXml = resultXml.CleanInvalidXmlChars();
                    var doc = new System.Xml.XmlDocument();
                    doc.LoadXml(resultXml);
                    var headArray  = doc.SelectNodes("/response/head");
                    string status = headArray[0].SelectSingleNode("code").InnerText;
                    string body = doc.SelectNodes("/response/body")[0].InnerXml;
                    if (status=="1"&&!string.IsNullOrWhiteSpace(body))
                    {
                        var bodyArray  = doc.SelectNodes("/response/body/record");
                        foreach (System.Xml.XmlNode item in bodyArray)
                        {
                            string taskid= item.SelectSingleNode("deal_id").InnerText;
                            string mobile = item.SelectSingleNode("phone").InnerText;
                            string receivetime = item.SelectSingleNode("recv_date").InnerText;
                            string content = item.SelectSingleNode("content").InnerText;
                            this.LogInfo("获取的上行信息=" + "1:" + mobile + " 2:" + taskid + " 3:" + content + " 4:" + receivetime  + " ");
                            this.NotifyReceiveMo(mobile, content);
                        }
                    }

  • 相关阅读:
    MQ消息队列(2)—— Java消息服务接口(JMS)
    MQ消息队列(1)—— 概念和使用场景
    SpringBoot — HelloWorld开发部署
    redis的配置文件介绍
    Redis info 参数详解
    10 分钟彻底理解 Redis 的持久化和主从复制
    Docker Yearning + Inception SQL审核平台搭建
    Inception SQL审核注解
    运行python脚本后台执行
    解决yum [Errno 256] No more mirrors to try
  • 原文地址:https://www.cnblogs.com/rengke2002/p/6805365.html
Copyright © 2011-2022 走看看