c#webclient在工作頁面上返回403和301。如何擺脫這個。這是我的代碼。沒有通過C#中的WebClient獲取網頁的頁面源代碼?
TimedWebClient wclient = new TimedWebClient();
//This is a object extend WebClient
byte[] pagesource = wclient.DownloadData(requestUrl);
UTF8Encoding objUTF8 = new UTF8Encoding();
string responseData = objUTF8.GetString(pagesource);
這適用於某些URL,但不與他人 例如:網址是:http://toyotaofmanhattan.com/
"The remote server returned an error: (403) Forbidden."}System.Exception {System.Net.WebException}
請幫我解決這個problem.Thank你。
它是一個https網址嗎? – liquidsnake786
它可能檢測到您沒有用戶代理並因此懷疑機器人或類似設備的事實。嘗試設置一個用戶代理;看到這個答案更多的信息:http://stackoverflow.com/a/2316128/1073107 – dash
只是使用嘗試趕上,所以如果URL不會加載顯示文本說例如抱歉不能加載具體的網址 – Sora