Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Http;
- using System.Threading.Tasks;
- public class Program
- {
- private readonly HttpClient Client;
- private readonly CookieContainer CookieContainer = new CookieContainer();
- public Program()
- {
- var handler = new HttpClientHandler() { CookieContainer = CookieContainer };
- Client = new HttpClient(handler) { BaseAddress = new Uri("https://icstrvl.ru") };
- CookieContainer.Add(new Cookie("__ydma", "afx2232_32324", "/", Client.BaseAddress.Host)); // Задаем статичную Cookie __ydma, адрес которой == базовому адресу клиента.
- }
- public static void Main() => new Program().Run().GetAwaiter().GetResult();
- private async Task Run()
- {
- _ = await Client.GetAsync("/"); // Отправляем пустой запрос для получения Cookie tracking
- var response = await Client.GetAsync("/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");
- Console.WriteLine(await response.Content.ReadAsStringAsync());
- }
- // Метод получения Cookie, но он по сути тут лишний.
- //private async Task<Cookie> GetCookieAsync(string name)
- //{
- // _ = await Client.GetAsync("/");
- // var cookies = CookieContainer.GetCookies(Client.BaseAddress);
- // return cookies[name];
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement