R
R
rocket_media2020-05-23 14:26:48
.NET
rocket_media, 2020-05-23 14:26:48

How to disable SSL when using WebClient?

Greetings, stranger!

I wrote a small console application for working with a telegram bot. And it works great on my laptop. But on the PC that I am going to use as a server for the application, an error occurs during the execution of this code:

try {
    var webClient = new WebClient();
    webClient.DownloadString($"{startUrl}/sendMessage?chat_id={messageFromId}&text=" + number.ToString());
}

 catch (Exception e){
    Console.WriteLine(e.ToString());
}


In Exception I see the following:

> System.Net.WebException: The SSL connection could not be established,
> see inner exception. Unable to read data from the transport
> connection: Удаленный хост принудительно разорвал существующее
> подключение..  ---> System.Net.Http.HttpRequestException: The SSL
> connection could not be established, see inner exception.  --->
> System.IO.IOException: Unable to read data from the transport
> connection: Удаленный хост принудительно разорвал существующее
> подключение..  ---> System.Net.Sockets.SocketException (10054):
> Удаленный хост принудительно разорвал существующее подключение.    ---
> End of inner exception stack trace ---    at
> System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError
> error, CancellationToken cancellationToken)    at
> System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16
> token)    at System.Net.FixedSizeReader.ReadPacketAsync(Stream
> transport, AsyncProtocolRequest request)    at
> System.Net.Security.SslStream.ThrowIfExceptional()    at
> System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult
> lazyResult)    at
> System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult
> result)    at
> System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult
> asyncResult)    at
> System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__65_1(IAsyncResult
> iar)    at
> System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult
> iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean
> requiresSynchronization)
> --- End of stack trace from previous location where exception was thrown ---


How can I, an illiterate person, overcome this dragon?

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2020-05-23
@BasiC2k

Before creating the webClient, insert:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls

This is VB.NET, I think you can translate it into C#.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question