diff options
author | Damien George <damien@micropython.org> | 2024-04-27 13:39:57 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-05-13 11:35:41 +1000 |
commit | bd610ff0160f8dad2b4a3592d5351b6029af5caa (patch) | |
tree | df70d819a63d5b85d7740d43fe2fb64726c47e08 /examples/network/https_client.py | |
parent | eb517a0a12c09b2ca8958c7481344c187a91b48f (diff) |
examples/network: Rename SSL examples to start with https.
It's better for discoverability to have these examples named `https_xxx.py`
rather than `http_xxx_ssl.py`.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'examples/network/https_client.py')
-rw-r--r-- | examples/network/https_client.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/network/https_client.py b/examples/network/https_client.py new file mode 100644 index 000000000..323971c0e --- /dev/null +++ b/examples/network/https_client.py @@ -0,0 +1,32 @@ +import socket +import ssl + + +def main(use_stream=True): + s = socket.socket() + + ai = socket.getaddrinfo("google.com", 443) + print("Address infos:", ai) + addr = ai[0][-1] + + print("Connect address:", addr) + s.connect(addr) + + s = ssl.wrap_socket(s) + print(s) + + if use_stream: + # Both CPython and MicroPython SSLSocket objects support read() and + # write() methods. + s.write(b"GET / HTTP/1.0\r\n\r\n") + print(s.read(4096)) + else: + # MicroPython SSLSocket objects implement only stream interface, not + # socket interface + s.send(b"GET / HTTP/1.0\r\n\r\n") + print(s.recv(4096)) + + s.close() + + +main() |