没有通过C#中的WebClient获取网页的页面源?

时间:2013-11-26 11:10:38

标签: c# exception webclient

c#webclient在工作页面上返回403和301。如何摆脱这个。这是我的代码。

TimedWebClient wclient = new TimedWebClient();
//This is a object extend WebClient

byte[]  pagesource = wclient.DownloadData(requestUrl);
UTF8Encoding objUTF8 = new UTF8Encoding();
string responseData = objUTF8.GetString(pagesource);

这适用于某些网址,但不适用于其他网址 例如:网址为:http://toyotaofmanhattan.com/

"The remote server returned an error: (403) Forbidden."}System.Exception  {System.Net.WebException}

请帮我解决这个问题。谢谢。

1 个答案:

答案 0 :(得分:-1)

尝试使用Fiddler。检查浏览器发送的内容以查看页面,以及您未发送的内容以获取错误。每页都可能有所不同。