請儘量看到這個帖子HttpClient Request like browser
response.EnsureSuccessStatusCode();
using (var responseStream = await response.Content.ReadAsStreamAsync())
using (var decompressedStream = new GZipStream(responseStream, CompressionMode.Decompress))
using (var streamReader = new StreamReader(decompressedStream))
{
return streamReader.ReadToEnd();
}
我做樣品我的機器上
全面的行動在這裏
public async Task<string> Index()
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "text/html,application/xhtml+xml,application/xml");
client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");
var httpMessage = await client.GetAsync("http://www.google.com");
httpMessage.EnsureSuccessStatusCode();
using (var responseStream = await httpMessage.Content.ReadAsStreamAsync())
using (var decompressedStream = new GZipStream(responseStream, CompressionMode.Decompress))
using (var streamReader = new StreamReader(decompressedStream))
{
return streamReader.ReadToEnd();
}
// return View();
}
example for get cookie from server
我試過了,但確實有效。 –
哇,我現在在我的本地機器上運行谷歌,看我編輯我的代碼 –
嗨Abdelrhman,我想瀏覽器具有谷歌會話相同的谷歌會話。在你的例子中,瀏覽器是否具有相同的會話,或只是顯示頁面?所以,如果google.com向我發送了一個cookie,我希望這個cookie也被髮送到瀏覽器。 –