获取网页的源代码时出现异常

时间:2017-07-06 15:02:49

标签: c# webclient webrequest

我尝试了以下两种方法来获取网页的源代码,但都无法打开网页。两种方法都通过异常远程服务器403禁止

string htmlstring = String.Empty;    
WebClient wc = new WebClient();
htmlstring = wc.DownloadString(website);

string htmlstring = String.Empty;
WebRequest request = WebRequest.Create(website);
WebResponse response = request.GetResponse();
Stream dt = response.GetResponseStream();
StreamReader sr = new StreamReader(dt);
htmlstring = sr.ReadToEnd();

0 个答案:

没有答案