Advertisement
Guest User

Untitled

a guest
May 27th, 2020
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Net.Http;
  4. using System.Threading.Tasks;
  5.  
  6. public class Program
  7. {
  8.     private readonly HttpClient Client;
  9.     private readonly CookieContainer CookieContainer = new CookieContainer();
  10.     public Program()
  11.     {
  12.         var handler = new HttpClientHandler() { CookieContainer = CookieContainer };
  13.         Client = new HttpClient(handler) { BaseAddress = new Uri("https://icstrvl.ru") };
  14.         CookieContainer.Add(new Cookie("__ydma", "afx2232_32324", "/", Client.BaseAddress.Host)); // Задаем статичную Cookie __ydma, адрес которой == базовому адресу клиента.
  15.     }
  16.  
  17.     public static void Main() => new Program().Run().GetAwaiter().GetResult();
  18.  
  19.     private async Task Run()
  20.     {
  21.         _ = await Client.GetAsync("/"); // Отправляем пустой запрос для получения Cookie tracking
  22.         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&lttt=1");
  23.         Console.WriteLine(await response.Content.ReadAsStringAsync());
  24.     }
  25.  
  26.     // Метод получения Cookie, но он по сути тут лишний.
  27.     //private async Task<Cookie> GetCookieAsync(string name)
  28.     //{
  29.     //    _ = await Client.GetAsync("/");
  30.     //    var cookies = CookieContainer.GetCookies(Client.BaseAddress);
  31.     //    return cookies[name];
  32.     //}
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement