Last active
April 16, 2017 19:24
-
-
Save SyNeto/ab58af6d95701baec411107c9d7fdf2d to your computer and use it in GitHub Desktop.
Micropython test main.py file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
def http_request(url, method="GET", **kwargs): | |
""" | |
Make an HTTP request, kwargs not implemented | |
""" | |
_, _, host, path = url.split('/', 3) | |
addr = socket.getaddrinfo(host, 80)[0][-1] # Gets ip and port tuple (xxx.xxx.xxx.xxx, xx) | |
sock = socket.socket() | |
sock.connect(addr) | |
sock.send(b'%s /%s HTTP/1.1\r\nHost: %s\r\n\r\n' % (method, path, host)) | |
while True: | |
data = sock.recv(4096) | |
if data: | |
print(str(data, 'utf8'), end='') | |
else: | |
break | |
sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment