[英]WebRequest with proxy throwing HTTP 405 method not allowed error
[英]Error 405 Method not Allowed on WebRequest
我正在嘗試從下面的頁面中獲取頁面代碼。 它給了我一個 405 錯誤。 如果我嘗試從主頁獲取頁面代碼,它可以正常工作,但從這個特定頁面我得到 Method not allowed,想法?
WebRequest request = WebRequest.Create("https://www.realtor.com/realestateandhomes-search/California/counties");
request.UseDefaultCredentials = true;
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
該網站認為您是機器人。
細節:
我用HttpClient
嘗試過(推薦:在收到非 200 響應代碼時不拋出異常),並檢查了響應 HTML。 這是重要的片段:
<p>
As you were browsing, something about your browser made us think you might be a bot. There are a few reasons this might happen, including:
</p>
<ul>
<li>You're a power user moving through this website with super-human speed</li>
<li>You've disabled JavaScript and/or cookies in your web browser</li>
<li>A third-party browser plugin is preventing JavaScript from running. Additional information is available in this
<a title='Third party browser plugins that block javascript' href='http://ds.tl/help-third-party-plugins' target='_blank'>
support article
</a>.
</li>
</ul>
如果您想要完整的響應,請嘗試運行以下命令:
async void LogResponse()
{
using System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
var response = await client.GetAsync("https://www.realtor.com/realestateandhomes-search/California/counties");
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
對 realtor.com, 405
的側面投訴(不允許在請求行中指定的方法)是一個相當糟糕的響應代碼; 一個403
(服務器理解請求,但拒絕滿足它。 )似乎更適合。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.