Test file upload interfaces

 

 

import requests

url = "http://xxxx/api/upload/opinion"
url_login = "http://xxxx/api/auth/login"
data = {"username":"test3","password":"123456"}
res = requests.post(url=url_login,data=data)
token = res.json()['data']['token']

headers = {"Authorization":"bearer %s" % token,
          }
file1 = open('20191113.docx','rb')

files = {'file':('20191113.docx',file1,'application/vnd.openxmlformats-officedocument.wordprocessingml.document')}
"""
application/vnd.openxmlformats-officedocument.wordprocessingml.document是抓包时得到
""" data1
= {"category":" Special projects " , " name " : " manned space station systems " , " Stage " : " Project development " , " Version " : " V20191025-144234 (before review) " , } RES = requests.post (url = url, = headers headers, Data = DATAl, Files = Files) Print (res.json () [ " MSG " ])

Explicitly set the file name, file type, and a request header

Guess you like

Origin www.cnblogs.com/wbw-test/p/11989323.html