Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey guys, I'm trying to download a file from a website that only supports TLS 1.3 using HttpClient, but it keeps giving me this error:

System.Security.Authentication.AuthenticationException: Authentication failed because the remote party sent a TLS alert: 'ProtocolVersion' ---> System.ComponentModel.Win32Exception (0x80090326): The message received was unexpected or badly formatted.``




Here's the file url: https://ksk-h7glm2.xyz/dl/ac95c389-31ae-416f-a8cd-fdfb5969d528.cbz

I already tried adding tls13 to the Security protocols but to no avail. What's interesting is that I'm able to use python and its requests library to download the file just fine; does windows 10 22h2 not support tls1.3? I tried adding a registry edit to "client" in the protocols for 1.3, but that doesn't do anything either. I would appreciate any help

What I have tried:

I already tried adding tls13 to the Security protocols but to no avail.
Posted
Updated 11-Apr-23 13:21pm
Comments
Graeme_Grant 11-Apr-23 19:03pm    
Please post your code so that we can see what you are doing.
u1923u12389h 11-Apr-23 19:12pm    
Yeah, it's a simple HttpClient making a post request:
using (var client = new HttpClient()) {
var resp = await client.PostAsync("https://ksk-h7glm2.xyz/dl/ac95c389-31ae-416f-a8cd-fdfb5969d528.cbz");
}

I'm thinking the issue is Window's SSL library has a cipher suite that is unavailable because python's requests library works fine with openssl
Graeme_Grant 11-Apr-23 19:20pm    
Download = get, not post.
u1923u12389h 11-Apr-23 20:07pm    
Yeah, in this case, it requires a post. On the site, doing a get request would redirect it back to the homepage. I tested the url with python and it needs a post. The odd thing is it works with the requests library, not with what .net uses.
Graeme_Grant 11-Apr-23 20:08pm    
The code below downloads the file with no issues. Hence why I posted it. 39,860KB, right?

1 solution

Here is an example of how to download a file. I am using a console app.
C#
using Microsoft.Extensions.DependencyInjection;

const string HttpClientKey = "CodeProjectHelp";

IHttpClientFactory? _httpClientFactory;
string url = "https://ksk-h7glm2.xyz/dl/ac95c389-31ae-416f-a8cd-fdfb5969d528.cbz";

CreateHttpClient();

using HttpClient client = _httpClientFactory!.CreateClient(HttpClientKey);
await using FileStream fileStream = File.Create("ac95c389-31ae-416f-a8cd-fdfb5969d528.cbz");
await using Stream httpStream = await client.GetStreamAsync(url);

await httpStream.CopyToAsync(fileStream);

Console.WriteLine("File Downloaded");
Console.ReadKey();

void CreateHttpClient()
{
    ServiceCollection builder = new();
    builder.AddHttpClient(HttpClientKey);
    ServiceProvider serviceProvider = builder.BuildServiceProvider();

    _httpClientFactory = serviceProvider.GetRequiredService<IHttpClientFactory>();
}
 
Share this answer
 
Comments
u1923u12389h 11-Apr-23 20:10pm    
Still gives the same issue. I think it has something to do with what Windows uses for its SSL library. There's either a problem with TLS fingerprints and them blocking me from downloading their file or TLS 1.3 is disabled or unsupported on my windows 10 os
Graeme_Grant 11-Apr-23 20:10pm    
Works fine here. Windows 11.
u1923u12389h 11-Apr-23 20:12pm    
Ah, that's probably it, I think windows 10 doesn't support TLS 1.3? Maybe it does, and my system is just bugged. I googled something about windows 10 not automatically enabled 1.3 so maybe that's the issue. I appreciate the help
Graeme_Grant 11-Apr-23 21:14pm    
Did the links provided solve your issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900