none
HttpWebRequest读取数据为乱码? RRS feed

  • 问题

  • 最近用HttpWebRequest 读取http://fund.jrj.com.cn/fhs/js/reportDates.js出现乱码,有时是正确的,有时确是如下的乱码,请问是什么原因?

    ?      5?? 勋 箕[垘[ E怰 2 ?8瀗奧蚲(軹?鱮锼鴝桖8蹄?t'#*挱靔耑]C矚同坒&a&a"&b"&b&`&`<芻<芻芶芶,芺,芺 芵 芵??F0|>琐Ys?乭&a>?WTg%? 

    代码如下:

    string url=@“http://fund.jrj.com.cn/fhs/js/reportDates.js”;

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
                    //声明一个HttpWebRequest请求

                    request.Timeout = 30000;

                    //设置连接超时时间
                    request.Headers.Set("Pragma", "no-cache");
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream streamReceive = response.GetResponseStream();
                    Encoding encoding = Encoding.GetEncoding(coding);
                    StreamReader streamReader = new StreamReader(streamReceive, encoding);
                    strResult = streamReader.ReadToEnd();

    2011年1月12日 14:24

答案

全部回复