首页 > 开发 > Xml > 正文

C#下xmlhttp 中文乱码完美解决方案

2020-02-03 13:54:51
字体:
来源:转载
供稿:网友

添加引用:

是ms xmlv2.6(不是v6.0,原因知道的同志给我答案)

 

 

using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using msxml2;

public partial class _default : system.web.ui.page 
...{
    
protected void page_load(object sender, eventargs e)
    
...{

    }

    
protected void button1_click(object sender, eventargs e)
    
...{

        
string msitename = textsarcher.text.trim();
        msxml2.xmlhttp xmlhttp 
= new msxml2.xmlhttp();
        
//string url = "http://www.xrss.cn/getservice.php?sitename=" + msitename + "";

        xmlhttp.open(
"get", url, falsenullnull);
        xmlhttp.send(
"");
        msxml2.xmldocument dom 
= new xmldocument();
        byte[] b 
= (byte[])xmlhttp.responsebody;
   
           //string flag = system.text.asciiencoding.utf8.getstring(b, 0, b.length);
        string andy = system.text.encoding.getencoding("gb2312").getstring(b).trim();

        
//response.write(url);
        
//response.write(flag);
        response.write(andy);
        
//response.end();
    }

}


 

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表