Здраствуйте, мне 12(неважно). При попытке отправить пост запрос на этот сайт -
https://kad.arbitr.ru/Kad/SearchInstances.
Выдает вот это. Что не так?
Код -
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
private static readonly HttpClient client = new HttpClient();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36");
}
private async void button1_MouseClick(object sender, MouseEventArgs e)
{
Dictionary<string, string> Params = new Dictionary<string, string>() {
{ "CaseNumbers:", "[А84-1719/2021]" },
{ "Count:", "25" },
{ "Courts:", "[]" },
{ "DateFrom:", "null" },
{ "DateTo:", "null" },
{ "Judges:", "[]" },
{ "Page:", "1" },
{ "Sides:", "[]" },
{ "WithVKSInstances:", "false" },
};
try
{
string result = await PostFormAsync("https://kad.arbitr.ru/Kad/SearchInstances", Params);
File.WriteAllText(@"C:\Users\forgu_000\Desktop\Новый текстовый документ.txt", result);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private static async Task<string> PostFormAsync(string url, Dictionary<string, string> data)
{
using (HttpContent content = new FormUrlEncodedContent(data))
{
using(HttpResponseMessage response = await client.PostAsync(url, content)) {
return await response.EnsureSuccessStatusCode().Content.ReadAsStringAsync();
}
}
}
}
}