擅长:python、mysql、java
<p><a href="http://docs.python.org/library/ssl#client-side-operation" rel="nofollow noreferrer">Example from the docs</a>:</p>
<pre><code>import socket, ssl, pprint
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# require a certificate from the server
ssl_sock = ssl.wrap_socket(s,
# http://curl.haxx.se/ca/cacert.pem
ca_certs="cacert.pem",
cert_reqs=ssl.CERT_REQUIRED)
ssl_sock.connect(('www.verisign.com', 443))
print repr(ssl_sock.getpeername())
print ssl_sock.cipher()
print pprint.pformat(ssl_sock.getpeercert())
# Set a simple HTTP request use httplib in actual code.
ssl_sock.write("""GET / HTTP/1.0\r
Host: www.verisign.com\r\n\r\n""")
# Read a chunk of data. Will not necessarily
# read all the data returned by the server.
data = ssl_sock.read()
print repr(data)[:79]
# note that closing the SSLSocket will also close the underlying socket
ssl_sock.close()
</code></pre>
<h3>输出</h3>
^{pr2}$
<h2><a href="https://stackoverflow.com/a/8498146/4279">Example with M2Crypto</a></h2>