docs/esp8266/tutorial: Make http_get sample function self contained.

pull/5221/head
Thiago Paes 2018-11-01 21:47:43 -03:00 zatwierdzone przez Damien George
rodzic d1ed73ca8f
commit 5463ab6df6
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -61,6 +61,7 @@ of the request you need to specify the page to retrieve.
Let's define a function that can download and print a URL::
def http_get(url):
import socket
_, _, host, path = url.split('/', 3)
addr = socket.getaddrinfo(host, 80)[0][-1]
s = socket.socket()
@ -74,8 +75,7 @@ Let's define a function that can download and print a URL::
break
s.close()
Make sure that you import the socket module before running this function. Then
you can try::
Then you can try::
>>> http_get('http://micropython.org/ks/test.html')