相关文章推荐

需要一个SslStream来封装NetworkStream,然后用这个SslStream来收发信息,方法如下:

  1 public static void HttpsConnect(string host, int port)
  3     using var tcp = new TcpClient();
  4     tcp.Connect(host, port);
  5     var stream = tcp.GetStream();
  6     var sslStream = new SslStream(stream, true);
  7     sslStream.AuthenticateAsClient(host);
  9     //发送数据
 10     sslStream.Write(requestData);
 12     //接受数据
 13     var responseBuffer = new byte[1024 * 1024];
 14     var receivedNum = sslStream.Read(responseBuffer, 0, responseBuffer.Length);
 
推荐文章