using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net.Http;
using CefSharp;
using CefSharp.WinForms;
using System.Text;
using System.Text.Json;
namespace WinFormsApp4
{
public partial class Form1 : Form
{
private ChromiumWebBrowser browser;
private readonly HttpClient http = new HttpClient();
string Wasm;
string Address = "https://kad.arbitr.ru/Kad/SearchInstances";
class Search {
public int Page { get; set; }
public int Count { get; set; }
public string[] Courts { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public Sides[] Sides { get; set; }
public Judges[] Judges { get; set; }
public string[] CaseNumbers { get; set; }
public bool WithVKSInstances { get; set; }
}
class Sides
{
public string Name { get; set; }
public int Type { get; set; }
public bool ExactMatch { get; set; }
}
class Judges
{
public string JudgeId { get; set; }
public int Type { get; set; }
}
public Form1()
{
InitializeComponent();
InitializeChromium();
}
private async void button1_Click(object sender, EventArgs e)
{
Search search = new Search()
{
CaseNumbers = Array.Empty<string>(),
Page = 1,
Count = 25,
Courts = Array.Empty<string>(),
DateFrom = null,
DateTo = null,
Sides = Array.Empty<Sides>(),
Judges = Array.Empty<Judges>(),
WithVKSInstances = false
};
try
{
var response = await PostJsonAsync(Address, search);
MessageBox.Show(response);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private async Task<string> PostJsonAsync(string url, Search obj)
{
UpdateWasm();
HttpContent content = new StringContent(JsonSerializer.Serialize(obj));
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, url);
var cookies = await Cef.GetGlobalCookieManager().VisitAllCookiesAsync();
var wasm = cookies.First(x => x.Name == "wasm").Value;
request.Content = content;
request.Headers.Add("Cookie", $"wasm={wasm}");
HttpResponseMessage response = await http.SendAsync(request, HttpCompletionOption.ResponseContentRead);
return await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync();
}
private void InitializeChromium()
{
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
browser = new ChromiumWebBrowser("https://kad.arbitr.ru/");
Controls.Add(browser);
browser.Dock = DockStyle.Fill;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
private void button2_Click(object sender, EventArgs e)
{
UpdateWasm();
}
private void UpdateWasm()
{
string script = "const btn = document.getElementById('b-form-submit').children[0].children[1]; btn.click();";
browser.ExecuteScriptAsync(script);
}
}
}