WebClient.DownloadString结果与浏览器结果不匹配

时间:2014-09-14 16:33:36

标签: c# encoding utf-8 webclient downloadstring

以下代码:

        WebClient WC = new WebClient();
        WC.Encoding = Encoding.UTF8;
        string Url = "http://www.tsetmc.com/tsev2/data/instinfodata.aspx?i=59266699437480384&c=64";
        return WC.DownloadString(Url);

代码返回:

�Q�T�MP�J�A|�^D����~���C�"�����l� ��;I&3=j=�iG�H9Ȓ�J�^� �j��T�Q=HH�'Qm�������1�hF�4�*�������{�x�\o?

当我在任何网络浏览器中访问该网址时,我得到:

12:29:45,A ,3540,3567,3600,3621,3690,3515,140,238204,849582597,1,20140914,122945;;1@2825@3523@3583@1700@1,1@2000@3522@3600@8700@2,1@500@3511@3640@2500@1,;19774,99736,1

有没有办法得到正确的字符串?

另外,我使用这个在线解码器,但我没有得到正确的答案: Universal Online Decoder

2 个答案:

答案 0 :(得分:0)

这应该有效:

    WebClient WC = new WebClient();
   // WC.Encoding = Encoding.UTF8;
    string Url = "http://www.tsetmc.com/tsev2/data/instinfodata.aspx?i=59266699437480384&c=64";
    return Encoding.UTF8.GetString(WC.DownloadString(Url));

答案 1 :(得分:0)

在DownloadString方法中使用Uri Object作为参数:

var url = String.Format(" http://www.tsetmc.com/tsev/data/instinfodata.aspx?i=59266699437480384&c=64");

var WC = new WebClient {Encoding = Encoding.UTF8};

返回WC.DownloadString(new Uri(url));