无法创建SSL/TLS安全通道,请求协助排查rtvs.sk站点访问问题
Hey there! I totally get how frustrating this is—spending 5 hours stuck on an SSL error when other sites work smoothly is the worst. Let's break this down and get your code working with rtvs.sk.
First, let's cover the most likely fixes (these solve similar issues all the time):
1. Add a proper User-Agent header
Most modern websites block requests with the default WebClient User-Agent (which looks outdated, like Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)). Browsers send a standard, modern UA string, and rtvs.sk might be rejecting your request purely because of this mismatch.
2. Let .NET handle TLS protocol automatically
You're using .NET Framework 4.7+, which automatically uses your system's configured TLS settings (like TLS 1.2, which rtvs.sk requires). Manually setting SecurityProtocol can actually limit what protocols are available—remove that line to let the framework pick the best, compatible protocol automatically.
Here's your modified code with these fixes:
string url1 = "https://www.rtvs.sk/televizia/archiv"; ServicePointManager.Expect100Continue = true; ServicePointManager.DefaultConnectionLimit = 9999; // Keep this temporarily for testing, but note: disabling certificate validation is insecure for production! ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true; string rets = ""; using (WebClient wc = new WebClient()) { wc.Proxy = null; // Add a browser-like User-Agent to avoid being blocked wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); try { // Use 'using' statements for streams to ensure proper resource disposal using (Stream stream = wc.OpenRead(url1)) using (StreamReader sr = new StreamReader(stream, Encoding.UTF8)) { rets = sr.ReadToEnd(); } } catch (Exception ex) { // Add error logging to get more details for further troubleshooting Console.WriteLine($"Error message: {ex.Message}"); if (ex.InnerException != null) { Console.WriteLine($"Inner error: {ex.InnerException.Message}"); } } }
If that still doesn't work, try these next steps:
- Check system TLS settings: Make sure TLS 1.2 is enabled on your Windows machine. Go to
Internet Options > Advanced > Securityand verify "Use TLS 1.2" is checked. - Switch to HttpClient:
WebClientis an older class—HttpClienthas better, more modern TLS support. Here's a quick example:using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"); try { rets = await client.GetStringAsync(url1); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } - Verify cipher suites: rtvs.sk might require specific TLS cipher suites that aren't enabled on your system. You can check the site's required cipher suites and ensure your system has them enabled via Windows Group Policy or registry settings.
A quick important note:
Disabling certificate validation with the callback is fine for testing, but in production, you should remove that line. Skipping validation exposes you to man-in-the-middle attacks—always let .NET validate certificates properly in live environments.
内容的提问来源于stack exchange,提问作者martin

