40 lines
840 B
Python
40 lines
840 B
Python
import requests
|
|
|
|
import aiohttp
|
|
from aiohttp import web, WSCloseCode
|
|
import asyncio
|
|
|
|
async def http_handler(request):
|
|
payload = await request.text()
|
|
print(payload)
|
|
|
|
url = 'http://192.168.185.166/turtle/send'
|
|
headers = {'content-type': 'application/json'}
|
|
r = requests.post(url, data=payload, headers=headers)
|
|
|
|
print(r.text)
|
|
|
|
return web.Response(text=r.text)
|
|
|
|
|
|
def create_runner():
|
|
app = web.Application()
|
|
app.add_routes([
|
|
web.post('/', http_handler),
|
|
])
|
|
return web.AppRunner(app)
|
|
|
|
|
|
async def start_server(host="127.0.0.1", port=4444):
|
|
runner = create_runner()
|
|
await runner.setup()
|
|
site = web.TCPSite(runner, host, port)
|
|
await site.start()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
loop = asyncio.get_event_loop()
|
|
loop.run_until_complete(start_server())
|
|
loop.run_forever()
|
|
|