話不多說,直接給案例
請求Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryj0QkLJMnALDH5DDw
1.查看請求為二進制文件的方式
直接用files模擬,每個Content-Disposition,寫個字段key-value
2.第二種方式
url = "http://test.quasar.oa.com:8082/assess/api/AssessObject/ImportStaff"
headers = {
"Accept": "application/json, text/plain, */*",
# content-type參數,如果我們通過form-data的方式上傳文件,我們發送post請求的時候,headers這個參數中一定不能要包括這個值,requests庫會幫忙添加這個元素,加了可能會報錯
# "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryNZB2Bg7I8L7EropZ",
"Cookie": config.config.cookie
}
path = (os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test.xlsx'))
files = {'file': open(path, 'rb')}
data={"PackageID":"616503661f42853cf46662ae"}
res = requests.post(url=url, headers=headers, files=files,data=data)