http://888.qq.com/info/liveodds/index.php?mod=europe&op=matchpankshow&lottery=jczq&betmid=566772&cid=82&isajax=1&ajaxType=2&_=1327064742410
 public static string GetResponse(string url)
        {            WebRequest myWebRequest = WebRequest.Create(url);            // Send the 'WebRequest' and wait for response.
            WebResponse myWebResponse = myWebRequest.GetResponse();            // Obtain a 'Stream' object associated with the response object.
            Stream ReceiveStream = myWebResponse.GetResponseStream();            Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            
            // Pipe the stream to a higher level stream reader with the required encoding format. 
            StreamReader readStream = new StreamReader(ReceiveStream, encode);
            Char[] read = new Char[256];            // Read 256 charcters at a time.    
            int count = readStream.Read(read, 0, 256);            StringBuilder s = new StringBuilder();            while (count > 0)
            {
                // Dump the 256 characters on a string and display the string onto the console.
                String str = new String(read, 0, count);
                s.Append(str);
                count = readStream.Read(read, 0, 256);
            }            // Release the resources of stream object.
            readStream.Close();            // Release the resources of response object.
            myWebResponse.Close();
            return s.ToString();
        }
用这个方法抓这个页面得到是乱码 怎么解决

解决方案 »

  1.   

    本帖最后由 net_lover 于 2012-01-20 21:35:44 编辑
      

  2.   

    英文操作系统 用不了System.Text.Encoding.GetEncoding("GB2312");
      

  3.   

    先读取页面字节流,转换成ascii字符串,然后取页面的charset
    结合httpResponse头里的字符编码进行综合判断charset,最后再把字节流转换成charset编码的字符串。
    这样就可以自适应页面编码了。
      

  4.   

    Encoding encode = System.Text.Encoding.GetEncoding(936);