Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following code returned an error:(400) bad request:
C#
sub = "https://www.sosyachting.com";
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); 
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00 | 0x30); //tls,tls1.1,tls1.2,ssl3
System.Net.WebClient wc = new System.Net.WebClient();
byte[] raw = wc.DownloadData(sub);
string webData = System.Text.Encoding.UTF8.GetString(raw);

AcceptAllCertifications is defined as:
C#
public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
    return true;
}


I am using VS2010 c#, windows 7.

What I have tried:

The code incorporates every suggestion I have found on the internet. Any other ideas would be greatly appreciated.
Posted
Updated 10-Aug-19 7:28am
v2

Because you are using an older Windows version and probably an older .NET version, this could be a TLS issue.
More information here: Transport Layer Security (TLS) best practices with the .NET Framework | Microsoft Docs[^]
The simplest way to solve this is to use .NET Framework 4.7 or later.
Also see: your-net-code-could-stop-working-in-june[^]
 
Share this answer
 
v2
Thank you. I had sort of decided the same thing but cannot install a higher version of NET on Windows 7. I am in the process of upgrading to Windows 10 and VS 2012 which hopefully will solve my problem.
 
Share this answer
 
Comments
Member 11170300 10-Aug-19 14:58pm    
Unfortunately, not resolved.

I am now running Visual Studio 2012 on Windows10 and targetting .NET4.5 but getting the same error message with unchanged code
Member 11170300 10-Aug-19 17:23pm    
I've now upgrade to .NET 4.8. Still failing.
Richard Deeming 13-Aug-19 13:15pm    
If you want to reply to a solution, click the "Have a Question or Comment?" button under that solution and post a comment.

DO NOT post your reply as a "solution".

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