I can't send a get request
I set all the headers, and try to catch cookies, there are no cookies, the headers are set, the server still gives 404
var cookieContainer = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler() { CookieContainer = cookieContainer }; ;
HttpClient client = new HttpClient(handler);
client.DefaultRequestHeaders.Add("Referer", "https://www.icstrvl.ru/srch_v4/index.html");
var html = await client.GetAsync("https://www.icstrvl.ru/srch_v4/index.html")
Console.WriteLine(html);
// Получаю куки \/
IEnumerable<Cookie> responseCookies13 = cookieContainer.GetCookies(new Uri(link)).Cast<Cookie>();
foreach (Cookie cookiew1 in responseCookies13)
{
Console.WriteLine(cookiew1.Name + ": " + cookiew1.Value);
cookieContainer.Add(cookiew1);
}
// Устанавливаю заголовки \/
var server = html.Headers.GetValues("Server").FirstOrDefault();
var ETag = html.Headers.GetValues("ETag").FirstOrDefault();
var Date = html.Headers.GetValues("Date").FirstOrDefault();
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36");
client.DefaultRequestHeaders.Add("Server", server);
client.DefaultRequestHeaders.Add("ETag", ETag);
client.DefaultRequestHeaders.Add("Date", Date);
string link2 = "https://www.icstrvl.ru/srch_v4/json/sdata.json?city=538625&cnt=14472441&spo=0&ct%5B%5D=5&tt%5B%5D=65977793&transport=all_transports&ad=2&ch=0&infant=0&ml%5B%5D=1771&d%5B%5D=7&date=2020-07-31&date1=2020-07-31&cur=0&mp=&nonstop=1&gf=1&pg=1&ver=1455&__mthd=getSearchResult<tt=1";
var html2 = await client.GetAsync(link2);
Console.WriteLine(html2);
If you run the code, you will see what headers and cookies are installed, after it returns 404, half a day I try to understand what is missing
0
Author: Prince Tag, 2020-05-26