首页 > 开发 > 综合 > 正文

利用WebClient获取远程数据(仅做备份)

2024-07-21 02:26:09
字体:
来源:转载
供稿:网友

     public dataset getdata(string httpurl)
              {
                     string xmlpath = @"http地址"; // 该地址不能包含中文
                     dataset ds = new dataset();
                     webclient wc = new webclient();
                     byte[] bt = wc.downloaddata(xmlpath);

                     xmldocument xd = new xmldocument();

                     string source = byte2string(bt);

                     xd.loadxml(source);

                     xmlnodereader xnr = new xmlnodereader(xd);

                     ds.readxml(xnr);

 

                     datatable dt = ds.tables[0];

 

                     this.datagrid1.datasource = ds;

                     this.datagrid1.databind(); 
  

                     return ds;  

              }

 

              public static string byte2string(byte[] bt)

              {

                     system.text.encoding encoding = system.text.encoding.getencoding("gb2312");

                     string str = encoding.getstring(bt);

                     return str;

              }

 

,欢迎访问网页设计爱好者web开发。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表