Skip to content

Instantly share code, notes, and snippets.

@SyNeto
Last active April 16, 2017 19:24
Show Gist options
  • Save SyNeto/ab58af6d95701baec411107c9d7fdf2d to your computer and use it in GitHub Desktop.
Save SyNeto/ab58af6d95701baec411107c9d7fdf2d to your computer and use it in GitHub Desktop.
Micropython test main.py file
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