WebClient.DownloadString结果与Browser结果不匹配2 [英] WebClient.DownloadString result is not match with Browser result 2

查看:235
本文介绍了WebClient.DownloadString结果与Browser结果不匹配2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码:

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

代码返回:

                                                                      H9Ȓ J ^  j  T Q=HH 'Qm       1 hF 4 *       { x \o?
/ b

$ b

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

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

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



还有,我使用这个在线解码器,但我没有得到正确答案:

  async void Main() 
{
using(var handler = new HttpClientHandler())
{
handler.AutomaticDecompression = DecompressionMethods.GZip;
使用(HttpClient client = new HttpClient(handler))
{
var result = await client.GetStringAsync(http://www.tsetmc.com/tsev2/data/instinfodata.aspx ?I = 59266699437480384和C = 64\" );
result.Dump();
}
}
}


The following code:

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

code returns:

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

when I visit that URL in any web browser, I get:

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

is there any way to get right string?

also, I use this online Decoder, but I don't get right answer: Universal Online Decoder

解决方案

In Linqpad you can run the below code, variation from Webclient. As you can see from the picture, its due to the Gzip compression which browser automatically handles.

async void Main()
{
    using (var handler = new HttpClientHandler())
    {
        handler.AutomaticDecompression = DecompressionMethods.GZip;
        using (HttpClient client = new HttpClient(handler))
        {
            var result = await client.GetStringAsync("http://www.tsetmc.com/tsev2/data/instinfodata.aspx?i=59266699437480384&c=64");
            result.Dump();
        }
    }
}

这篇关于WebClient.DownloadString结果与Browser结果不匹配2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆