文章17
标签2
分类9

关于Python的http

Http服务器

使用Sanic

from sanic import HTTPResponse, Sanic, json

初始化定义

app = Sanic('test')

设置路径

@app.route('/json')
async def json_return(request) :
    begin = request.args.get('begin')    #参数在args.get('name')里
    if begin is None:    #如果没有begin的参数,则为None
        pass

运行

def main():
    app.run(host = '127.0.0.1', port = 2054)

其他详细教程请跳转Sanic文档

Http请求

使用aiohttp库进行请求

import asyncio
import aiohttp

访问方法

async def get_text(session, url) :
    async  with session.get(url) as response :
        return await response.text( )
url = 'http://127.0.0.1:2054/path?param1=a&&param2=b'
async with aiohttp.ClientSession() as session :
                result = await get_text(session, url)
本文作者:admin
本文链接:https://banned.top/archives/43/
版权声明:本文采用 CC BY-NC-SA 3.0 CN 协议进行许可

0 评论

'