2014-08-27 00:13:38 +00:00
|
|
|
import uasyncio as asyncio
|
2014-04-20 03:27:43 +00:00
|
|
|
|
|
|
|
@asyncio.coroutine
|
|
|
|
def print_http_headers(url):
|
|
|
|
reader, writer = yield from asyncio.open_connection(url, 80)
|
|
|
|
print(reader, writer)
|
|
|
|
print("================")
|
|
|
|
query = "GET / HTTP/1.0\r\n\r\n"
|
2014-05-31 21:41:45 +00:00
|
|
|
yield from writer.awrite(query.encode('latin-1'))
|
2014-04-20 03:27:43 +00:00
|
|
|
while True:
|
|
|
|
line = yield from reader.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
if line:
|
|
|
|
print(line.rstrip())
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
url = "google.com"
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
#task = asyncio.async(print_http_headers(url))
|
|
|
|
#loop.run_until_complete(task)
|
2014-10-23 21:03:27 +00:00
|
|
|
loop.run_until_complete(print_http_headers(url))
|
2014-04-20 03:27:43 +00:00
|
|
|
loop.close()
|