中找到。
您能告诉我以下几点吗?
在localhost:8900
上有aiohttp服务器在运行
当我做一个请求(使用python2模块请求)从python
requests.get("http://127.0.01:8900/api/bgp/show-route",
data={'topo':"switzerland",
'pop':"zrh",
'prefix':"1.1.1.1/32"})
在aiohttp服务器中定义了一个路由
app.router.add_route("GET", "/api/bgp/show-route", api_bgp_show_route)
被像
一样处理def api_bgp_show_route(request):
pass
问题是:我如何在服务器端检索请求的数据部分?含义{'topo':"switzerland", 'pop':"zrh", 'prefix':"1.1.1.1/32"}
啊,data
部分是这样访问的
await request.json()
你可以在官方的aiohttp文档
这取决于你想要的数据格式。
获取字符串:
request.text()
获取字节:
request.read()
获取JSON字典(注意,如果数据格式错误,将抛出JSON .decoder. jsondecodeerror):
request.json()
您可以使用
访问POST请求体数据if request.body_exists:
print(await request.read())