Achieve openssl connect command functionality using C#

Sep 21 2021 6:32 AM

I have a fairly simple c# application(.net core 2.0) which sends jsons to an API. API consumes json and sends an acknowledgement.

This c# application is hosted on linux(artefacts generated using command - dotnet publish -C release --self-contained -runtime rhel-X64) and run from a datastage job. While running it from job I got the following error 

2021-09-03 02:23:28.7462|ERROR||One or more errors occurred. (The SSL connection could not be established, see inner exception.)

Now, I tried running openSSL command openssl s_client connect apiurl:443 on linux machine(where my datastage job is running), handshake was successful and there was no error.

1: Why am I getting this error when trying to connect from c#, am I missing anything here?.
2. Is there any way to achieve through c# code, what openssl s_client connect command does. Like any package or DLL available for c# which provides predetermined methods/functionality (precisely Connect method which takes url and port number as arguments and returns whether handshake was successful or not)?