Hi, dear stranger!
I made a console application for my telegram bot. On my laptop it works perfectly, but on my PC which i want to use as a server this code gets an error. I spent the whole day trying to fix it and went through a lot of similar topics over here but didn't find any solution.
The trouble appears at this part of code:
try {
var webClient = new WebClient();
webClient.DownloadString($"{startUrl}/sendMessage?chat_id={messageFromId}&text=" + number.ToString());
}
catch (Exception e){
Console.WriteLine(e.ToString());
}
How can i avoid SSL certificate since i am not looking for a real security here?
The error is below:
> 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 ---
What i've already tried:
1) Puting this before the WebClient request. Doesn't help:
ServicePointManager.ServerCertificateValidationCallback +=
delegate (object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
2) Using delegates to disable SSL
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
3) Your idea is next?
Or may be i just was using wrongly the previous solutions? Don't pass by, let's try your ideas!
Thanks!