當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby SSLSocket.open用法及代碼示例

本文簡要介紹ruby語言中 OpenSSL::SSL::SSLSocket.open 的用法。

用法

open(remote_host, remote_port, local_host=nil, local_port=nil, context: nil)

創建 SSLSocket 的新實例。 remote host_ 和 remote port_ 用於打開 TCPSocket 。如果指定了local host_ 和local port_,則在本地使用這些參數來建立連接。如果提供了context,則 SSL Sockets 初始參數將從上下文中獲取。

例子

sock = OpenSSL::SSL::SSLSocket.open('localhost', 443)
sock.connect # Initiates a connection to localhost:443

使用 SSLContext:

ctx = OpenSSL::SSL::SSLContext.new
sock = OpenSSL::SSL::SSLSocket.open('localhost', 443, context: ctx)
sock.connect # Initiates a connection to localhost:443 with SSLContext

相關用法


注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 SSLSocket.open。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。