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

  • 相关阅读:
    JQuery 简单实现折叠菜单
    机械迷城攻略2
    ffmpeg视频转换及截图
    机械迷城攻略3
    SQL:清空数据库所有数据
    .net发送邮件outlook中文乱码
    我读我的Book
    转:精妙SQL语句收集
    SQL server 动态查询(表名或字段动态),并且获取想得到的返回值结果
    软件开发中,这些文档你用到了吗
  • 原文地址:https://www.cnblogs.com/rengke2002/p/6805365.html
Copyright © 2011-2022 走看看