HttpRequest:

 

代码
static class WebFunc   
{   
    
private static CookieContainer cookie = new CookieContainer();   
    
private static string contentType = "application/x-www-form-urlencoded";   
    
private static string accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-silverlight-2-b1, */*";   
    
private static string userAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)";   
  
    
public static string GetHtmlEx(string url, Encoding encoding)   
    {   
        HttpWebRequest request 
= (HttpWebRequest)WebRequest.Create(url);   
        request.UserAgent 
= userAgent;   
        request.ContentType 
= contentType;   
        request.CookieContainer 
= cookie;   
        request.Accept 
= accept;   
        request.Method 
= "get";   
  
        WebResponse response 
= request.GetResponse();   
        Stream responseStream 
= response.GetResponseStream();   
        StreamReader reader 
= new StreamReader(responseStream, encoding);   
        String html 
= reader.ReadToEnd();   
        response.Close();   
  
        
return html;   
    }   
}  

 

WebClient:

 

 

System.Net.WebClient wc = new System.Net.WebClient();   
Byte[] pageData 
= wc.DownloadData("网页地址");   
string s= System.Text.Encoding.Default.GetString(pageData);  

 

 

相关文章:

  • 2022-12-23
  • 2021-08-26
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
  • 2021-09-25
  • 2021-10-15
猜你喜欢
  • 2021-12-12
  • 2021-11-13
  • 2022-12-23
  • 2021-08-15
  • 2021-08-01
  • 2022-02-09
  • 2022-12-23
相关资源
相似解决方案