SSL handshake failed due to unexpected packet format Leave a comment

I am trying to connect to a Monero stage net node to make some basic RPC calls and start building a library for working with Monero however I am getting an SSL error when connectiong.

using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using Monero;
using Newtonsoft.Json;

namespace Monero
{
    public class Request
    {
        public readonly string jsonrpc = "2.0";
        public readonly string id = "0";
        public readonly string METHOD = "get_version";
    }
}

namespace Monero_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Monero.Request c1 = new Monero.Request();
            string json = JsonConvert.SerializeObject(c1);
            Console.WriteLine("Json = {0}", json);

            HttpClient client = new HttpClient();
            try
            {
                var content = new StringContent(json, Encoding.UTF8, "application/json");
                var response = client.PostAsync("https://monero-stagenet.exan.tech:38081/json_rpc", content);
                Console.WriteLine(response.Result.RequestMessage.Content.ReadAsStringAsync().Result); 
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
            }

            Console.ReadKey();
        }
    }
}

error:

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.IO.IOException: The handshake failed due to an unexpected packet format.
   at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---

How would I go about rectifying this?

Leave a Reply

Your email address will not be published. Required fields are marked *