美文网首页
requests库发送GET、POST请求

requests库发送GET、POST请求

作者: 菜鸟瞎编 | 来源:发表于2019-08-23 13:40 被阅读0次
    import requests
    import json
    
    url = "http://192.168.10.153:5000/modeltest/hello"
    
    
    url2 = "http://192.168.10.153:5000/modeltest/bye"
    
    req = {"key":"value"}
    req2 = {"data":"Hi."}
    req3 = {"data":"BYE."}
    
    ret = requests.get(url, params=req2)
    print(ret.text)
    ret = requests.get(url2, params=req3)
    print(ret.text)
    
    ret=requests.post(url, data=json.dumps(req))
    print(ret.text)
    ret=requests.post(url, data=json.dumps(req2))
    print(ret.text)
    
    ret=requests.post(url2, data=json.dumps(req))
    print(ret.text)
    ret=requests.post(url2, data=json.dumps(req3))
    print(ret.text)
    

    使用flask request解析GET、POST请求

    from flask import request
    import json
        if request.method == "POST":
            data = request.get_data()
            data_d =  json.loads(data)
        elif request.method == "GET":
            data_d = request.args.to_dict()
    

    相关文章

      网友评论

          本文标题:requests库发送GET、POST请求

          本文链接:https://www.haomeiwen.com/subject/hcozsctx.html