python调用post请求方式

调用post请求使用json参数实例:

data = {"flow": requestData, "upload_name": "123", "upload_time": "2020-06-10 10:20:30",
        "file_name": "20200610.zip"}

response = requests.post(url, data=data)
if response.status_code == 200:
    text = json.loads(response.text)
    print(text)

调用post请求使用form表单参数实例:

files = {'flow': (path, open(path, "rb")),
         'upload_name': (None, 'szh'),
         'upload_time': (None, '2020-06-10 10:20:30'),
         'file_name': (None, '20200610.zip')
         }
response = requests.request("POST", url, files=files)

if response.status_code == 200:
    text = json.loads(response.text)
    print(text)

以上是以流的形式作为参数访问post请求的,所以以上接口实用与图片或者压缩包其他文件流的形似

你可能感兴趣的:(个人总结,python,json,post)