我試圖向kicksusa.com發出請求。如果我從任何瀏覽器發出請求,我會得到完整的HTML,但是,我似乎無法以返回相同HTML的方式來模擬請求,而是得到'請求失敗'。信息。HttpClient - 返回的瀏覽器內容不同
任何幫助表示讚賞
我的代碼:
HttpClientHandler httpClientHandler = new HttpClientHandler()
{
//Proxy = proxy,
AllowAutoRedirect = true,
MaxAutomaticRedirections = 15,
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate | DecompressionMethods.None
};
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Host", "www.kicksusa.com");
client.DefaultRequestHeaders.Add("Connection", "keep-alive");
client.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1");
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36");
client.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate, sdch");
client.DefaultRequestHeaders.Add("Accept-Language", "en-GB,en-US;q=0.8,en;q=0.6");
var _response = await client.GetAsync("http://www.kicksusa.com/jordan-craig/oil-stain-slub-tee-army-green-8909ag.html");
if (_response.IsSuccessStatusCode)
{
var _html = await _response.Content.ReadAsStringAsync();
}
提琴手道頭:
Host: www.kicksusa.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
使用Fiddler,並將每個請求作爲序列化的線索進行比較。 – Amy
我已經完成了這項工作 - 仍然沒有運氣,請參閱編輯 –
該網站無論如何都使用javascript加載所有內容,因此即使您管理得到的是類似於瀏覽器的確切響應,它也不會對您有太大幫助,因爲它不會包含任何內容有用的信息(只是一個通知,你必須啓用JavaScript)。您需要渲染該網站(使用CefSharp.OffScreen或其他用於此目的的工具)執行它的JavaScript。 – Evk