日期:2014-05-18 浏览次数:20889 次
static public int GetHtml(HttpWebRequest request, ref string strContent) { try { strContent = ""; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); if (response.ContentEncoding.ToLower().Contains("gzip")) { responseStream = new GZipStream(responseStream, CompressionMode.Decompress, true); } else if (response.ContentEncoding.ToLower().Contains("deflate")) { responseStream = new DeflateStream(responseStream, CompressionMode.Decompress); } string strCharacterSet = response.CharacterSet; if (strCharacterSet.Contains("ISO-8859-1")) { strCharacterSet = "gbk"; } StreamReader readStream = new StreamReader(responseStream, System.Text.Encoding.GetEncoding(strCharacterSet)); strContent = readStream.ReadToEnd(); responseStream.Close(); response.Close(); return 0; } catch(Exception ex) { CMyFun.WriteLog(ex.ToString()); return -1; } }