日期:2014-05-17  浏览次数:20761 次

c#写文件,字符串全是乱码。
        public static void WriteFile()
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;
            strPath += "b.html";
            string url = "http://www.wolongyin.com/loginGame.jsp?sid=1002";
            string sException = null;
            try
            {
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
                webRequest.Accept = "*/*";
                webRequest.Method = "GET";
                webRequest.Headers.Add("Accept-Language", "zh-CN");
                webRequest.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
                webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
                webRequest.Headers.Add("TGClient", "yes");
                webRequest.Host = "www.wolongyin.com";
                webRequest.KeepAlive = true;
                HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
                Stream streamReceive = response.GetResponseStream();
                MessageBox.Show(((int)response.StatusCode).ToString());
                MessageBox.Show((response.CharacterSet).ToString());
                StreamReader streamReader = new StreamReader(streamReceive, Encoding.GetEncoding(response.CharacterSet));