We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ec5f8db commit 4f2d59eCopy full SHA for 4f2d59e
1 file changed
examples/network/http_client_ssl.py
@@ -0,0 +1,36 @@
1
+try:
2
+ import usocket as _socket
3
+except:
4
+ import _socket
5
6
+ import ussl as ssl
7
8
+ import ssl
9
+
10
11
+def main(use_stream=True):
12
+ s = _socket.socket()
13
14
+ ai = _socket.getaddrinfo("google.com", 443)
15
+ print("Address infos:", ai)
16
+ addr = ai[0][4]
17
18
+ print("Connect address:", addr)
19
+ s.connect(addr)
20
21
+ s = ssl.wrap_socket(s)
22
+ print(s)
23
24
+ if use_stream:
25
+ # Both CPython and MicroPython SSLSocket objects support read() and
26
+ # write() methods.
27
+ s.write(b"GET / HTTP/1.0\n\n")
28
+ print(s.read(4096))
29
+ else:
30
+ # MicroPython SSLSocket objects implement only stream interface, not
31
+ # socket interface
32
+ s.send(b"GET / HTTP/1.0\n\n")
33
+ print(s.recv(4096))
34
35
36
+main()
0 commit comments