InBlock.gif public string GetHtml( string url)
InBlock.gif        {
InBlock.gif                 string code = DecodeData(url);
InBlock.gif                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
InBlock.gif                request.Timeout = 30000;
InBlock.gif                request.Headers.Set( "Pragma", "no-cache");
InBlock.gif                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
InBlock.gif                Stream streamReceive = response.GetResponseStream();
InBlock.gif                Encoding encoding = code != string.Empty ? Encoding.GetEncoding(code.ToUpper()) : Encoding.Default;
InBlock.gif                StreamReader streamReader = new StreamReader(streamReceive, encoding);
InBlock.gif                 string strResult = streamReader.ReadToEnd();
InBlock.gif                streamReader.Close();
InBlock.gif                streamReader.Dispose();
InBlock.gif                 return strResult;
InBlock.gif        }
InBlock.gif //http://blog.sunmast.com/natas/archive/2004/10/30/989.aspx,略有改动.        
InBlock.gif
InBlock.gif         private string DecodeData( string Url)
InBlock.gif        {
InBlock.gif                WebRequest r = WebRequest.Create(Url);
InBlock.gif                WebResponse w = r.GetResponse();
InBlock.gif                 //            
InBlock.gif                 //     first     see     if     content     length     header     has     charset     =     calue            
InBlock.gif                 //            
InBlock.gif                String charset = string.Empty;
InBlock.gif                String ctype = w.Headers[ "content-type"];
InBlock.gif                 if (ctype != null)
InBlock.gif                {
InBlock.gif                         int ind = ctype.IndexOf( "charset=");
InBlock.gif                         if (ind != -1)
InBlock.gif                        {
InBlock.gif                                charset = ctype.Substring(ind + 8);
InBlock.gif                        }
InBlock.gif                }
InBlock.gif                 //     save     data     to     a     memorystream            
InBlock.gif                MemoryStream rawdata = new MemoryStream();
InBlock.gif                 byte[] buffer = new byte[1024];
InBlock.gif                Stream rs = w.GetResponseStream();
InBlock.gif                 int read = rs.Read(buffer, 0, buffer.Length);
InBlock.gif                 while (read > 0)
InBlock.gif                {
InBlock.gif                        rawdata.Write(buffer, 0, read);
InBlock.gif                        read = rs.Read(buffer, 0, buffer.Length);
InBlock.gif                }
InBlock.gif                rs.Close();
InBlock.gif                 //            
InBlock.gif                 //     if     ContentType     is     null,     or     did     not     contain     charset,     we     search     in     body            
InBlock.gif                 //            
InBlock.gif                 if (charset == null)
InBlock.gif                {
InBlock.gif                        MemoryStream ms = rawdata;
InBlock.gif                        ms.Seek(0, SeekOrigin.Begin);
InBlock.gif                        StreamReader srr = new StreamReader(ms, Encoding.ASCII);
InBlock.gif                        String meta = srr.ReadToEnd();
InBlock.gif                         if (meta != null)
InBlock.gif                        {
InBlock.gif                                 int start_ind = meta.IndexOf( "charset=");
InBlock.gif                                 int end_ind = -1;
InBlock.gif                                 if (start_ind != -1)
InBlock.gif                                {
InBlock.gif                                        end_ind = meta.IndexOf( "\"", start_ind);
InBlock.gif                                         if (end_ind != -1)
InBlock.gif                                        {
InBlock.gif                                                 int start = start_ind + 8;
InBlock.gif                                                charset = meta.Substring(start, end_ind - start + 1);
InBlock.gif                                                charset = charset.TrimEnd( new Char[] { '>', '"' });
InBlock.gif                                        }
InBlock.gif                                }
InBlock.gif                        }
InBlock.gif                }
InBlock.gif                 return charset.ToString();
InBlock.gif        }