HTTP 协议规定 POST 提交的数据必须放在消息主体(entity-body)中,但协议并没有规定数据必须使用什么编码方式。常见的有四种编码方式,今天就做下multipart/form-data第二种常见编码方式。
第一种常见的已经发布了:http://blog.csdn.net/luo2424348224/article/details/79637524
这又是一个常见的 POST 数据提交的方式。我们使用表单上传文件时,必须让 form 的 enctyped 等于这个值,下面是示例
import requests import json CONFIG = { 'url': 'http://192.168.90.10:8888/', 'headers': {'Content-Type': 'multipart/form-data '} } data = {'content': 'hello', 'digital': '0', 'punctuate': '1', 'engModel': '2'} url = CONFIG['url'] headers = CONFIG['headers'] response = requests.post(url=url, files=data,headers=headers,timeout=1) print(response.content)