Как везде сказано в Интернете, создан частный статический HTTP-клиент только для чтения, который повторно используется во всем приложении, но рукопожатие SSL/TLS1.2 происходит при каждом запросе, из-за чего получение ответа на него занимает почти 6 секунд. каждый запрос, который я делаю. вот мой код, в котором я пытаюсь отправить массив байтов на сервер частями. Я использую dotnet6.
private static readonly HttpClient client = new HttpClient(new HttpClientHandler
{
Credentials = new NetworkCredential("admin", "private"),
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) =>
true,
CheckCertificateRevocationList = true,
PreAuthenticate = true,
//UseCookies = true,
//CookieContainer = cookieContainer,
});
private async void button1_Click(object sender, EventArgs e)
{
//System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls| SecurityProtocolType.Tls13;
try
{
string http = "https://";
string fwupdate = "/fwup_install";
string fwreset = "/fwup_reset";
string ip = txt_ip.Text;
byte[] Data = null;
byte[] array1 = null;
string filePath = "D:\\fw\\iol_mix_mp_https.fwu";
Data = File.ReadAllBytes(TxT_SelectedFwuFile.Text);
var url = http + ip + fwupdate;
HttpContent content = new StringContent("size=" + Data.Length);
var response = await client.PostAsync(url, content);
richTextBox1.Text = richTextBox1.Text + ("Step1 : " + response.StatusCode);
int sendbytes = 0;
int Var = 1024 * 32;
int Len = Convert.ToInt32(Data.Length / Var);
int Counter = 0;
while (Data.Length > sendbytes)
{
//Thread.Sleep(1000);
if (Counter < Len)
{
array1 = new byte[Var];
for (int i = 0; i < array1.Length; i++)
{
if (sendbytes < Data.Length)
{
array1 = Data[sendbytes];
sendbytes++;
}
else
{
break;
}
}
Counter++;
// textBox1.Text = Counter.ToString();
}
else
{
array1 = new byte[Data.Length - (Var * Len)];
//textBox1.Text += "Remaining Array Length = " + array1.Length.ToString();
for (int i = 0; i < array1.Length; i++)
{
array1 = Data[sendbytes];
sendbytes++;
}
}
ByteArrayContent Bytcontent = new ByteArrayContent(array1);
Bytcontent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
var response1 = await client.PostAsync(url, Bytcontent);
richTextBox1.Text = richTextBox1.Text + (response1.StatusCode);
}
}
catch (Exception ex)
{
richTextBox1.Text = richTextBox1.Text + ex.Message;
richTextBox1.Text = richTextBox1.Text + ex.InnerException;
}
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "FWU file|*.fwu*";
ofd.Title = "Load FWU file";
if (ofd.ShowDialog() == DialogResult.OK)
{
TxT_SelectedFwuFile.Text = ofd.FileName;
}
}
private void Form1_Load(object sender, EventArgs e)
{
TxT_SelectedFwuFile.ReadOnly = true;
}
}
enter code here
Подробнее здесь: https://stackoverflow.com/questions/781 ... shake-on-e
C# HTTPClient не использует повторно сеанс SSL/TLS1.2 и выполняет рукопожатие при каждом запросе. ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение