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
a5d07c3a
Commit
a5d07c3a
authored
Apr 02, 2016
by
Paul Sokolovsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/http_client.py: Improve CPython compatibility in stream mode.
parent
a5d2af79
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
examples/network/http_client.py
examples/network/http_client.py
+8
-6
No files found.
examples/network/http_client.py
View file @
a5d07c3a
try
:
import
usocket
as
_
socket
import
usocket
as
socket
except
:
import
_
socket
import
socket
s
=
_
socket
.
socket
()
s
=
socket
.
socket
()
ai
=
_
socket
.
getaddrinfo
(
"google.com"
,
80
)
ai
=
socket
.
getaddrinfo
(
"google.com"
,
80
)
print
(
"Address infos:"
,
ai
)
addr
=
ai
[
0
][
4
]
...
...
@@ -14,8 +14,10 @@ print("Connect address:", addr)
s
.
connect
(
addr
)
if
0
:
# MicroPython rawsocket module supports file interface directly
s
.
write
(
"GET / HTTP/1.0
\n\n
"
)
# MicroPython socket objects support stream (aka file) interface
# directly, but the line below is needed for CPython.
s
=
s
.
makefile
(
"rwb"
,
0
)
s
.
write
(
b"GET / HTTP/1.0
\n\n
"
)
print
(
s
.
readall
())
else
:
s
.
send
(
b"GET / HTTP/1.0
\n\n
"
)
...
...
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