Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
4f2d59e8
Commit
4f2d59e8
authored
Apr 02, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/http_client_ssl.py: HTTPS client example.
parent
ec5f8db4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
examples/network/http_client_ssl.py
examples/network/http_client_ssl.py
+36
-0
No files found.
examples/network/http_client_ssl.py
0 → 100644
View file @
4f2d59e8
try
:
import
usocket
as
_socket
except
:
import
_socket
try
:
import
ussl
as
ssl
except
:
import
ssl
def
main
(
use_stream
=
True
):
s
=
_socket
.
socket
()
ai
=
_socket
.
getaddrinfo
(
"google.com"
,
443
)
print
(
"Address infos:"
,
ai
)
addr
=
ai
[
0
][
4
]
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
\n\n
"
)
print
(
s
.
read
(
4096
))
else
:
# MicroPython SSLSocket objects implement only stream interface, not
# socket interface
s
.
send
(
b"GET / HTTP/1.0
\n\n
"
)
print
(
s
.
recv
(
4096
))
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment