postman中 的一個請求接口,post請求
請求特點:其他請求參數均正常,text類型,只有file字段是file類型
捕捉了一下,
這樣的post請求,用headers為 Content-Type 用Application/Json 或 Application/x-www-form-urlencoded,這兩種常用 json或form,python post請求。均無法請求成功,返回500錯誤。
請求 抓包,headers 中 的Content-Type:multipart/form-data 注釋,只要上面那個
解決方法如上。 python 中代碼:
url = '%s:18080/oss/file/upload' % url
files = {'file':('front.png',open('C:/Users/fang/front.png','rb'),'image/png')}
headers = {'Postman-Token':'fbb65c0f-ce30-4183-9ee3-616c535a9977'}
data = originmessage.youzanOSSUPLoad.copy() # data 是個dict data中字段比較多,一起upLoad中
re = requests.post(url,headers=headers,data=data,files=files)
print(re.text,re.json())
file圖片文件,直接發送files參數。其他字段發送data參數即可
關鍵點:headers 中 content-type 一定要刪除, 只發送 token 相關即可。
寫這個請求的時候,查了資料,與正常請求方式麻煩點,記錄下