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);
                        }
                    }

  • 相关阅读:
    js01
    js---18miniJquery
    js---17继承中方法属性的重写
    js---16继承
    js---16原型链
    js---15深拷贝浅拷贝 原型链
    js---14公有私有成员方法
    js---13 this call apply
    js---12对象创建方式,构造器,原型
    ESXi导出的CentOS7 ovf文件导入到workstation 无法打开GUI登录界面的问题解决方案
  • 原文地址:https://www.cnblogs.com/rengke2002/p/6805365.html
Copyright © 2011-2022 走看看