How to do HTTPS with TcpClient just like HttpWebRequest does?

前端 未结 1 1678
不知归路
不知归路 2021-01-21 12:33

I\'ve got a communication system based on TcpClient, and it works great except for when it\'s doing HTTPS to a particular IP. Then it starts to fail.

By using a browser

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-21 13:12

    Wouldn't you know it, after I spend the time forming the question is when I stumble upon the answer.

    Here's the relevant documentation: jpsanders blog entry

    The important part was this:

    If the stack from the exception includes something similar to this: System.IO.IOException: Authentication failed because the remote party has closed the transport stream. It is possible that the server is an older server does not understand TLS and so you need to change this as specified in the 915599 kb to something like this: ServicePointManager.SecurityProtocol= SecurityProtocolType.Ssl3;Before you make any HTTPS calls in your application.

    So I change my accepted protocols to this: (removing the possibility of TLS)

    SslProtocols protocol = SslProtocols.Ssl2 | SslProtocols.Ssl3;
    

    And everything works great.
    I was allowing TLS, so it tries that first, and the server doesn't support it, so the stream is closed. The next time it uses Ssl2 or Ssl3 and everything's fine. Or something like that. It works, I'm a happy panda.

    0 讨论(0)
提交回复
热议问题