我正在尝试上传图片,并将其设置为某些系统中队友的个人资料。 我设法执行了这个请求,并使用Postman成功上传了图像,但不幸的是,当复制生成的代码/由我自己在IDE中编写代码时,它不起作用...
payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"PATH/TO/IMAGE.JPG\"\r\nContent-Type: text/plain\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'Authorization': "Basic
xxxxxxxxxxxxxxxxxxxxxxxxxxx",
'Accept': "*/*",
'Cache-Control': "no-cache",
'Host': "<host.of.site>",
'Content-Type': "multipart/form-data; boundary=--------------------------613416014226243256356192",
'Accept-Encoding': "gzip, deflate",
'Content-Length': "259378",
'Connection': "keep-alive",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
以下是文档中必填字段:
POST /api/gateway.php/sample/v1/employees/1/photo/ HTTP/1.0
Host: api.x.com
Content-Type: multipart/form-data; boundary=----MultiPart-Mime-Boundary----
Content-Length: 520
------MultiPart-Mime-Boundary----
Content-Disposition: form-data; name="file"; filename="photo.jpg"
Content-Type: text/plain
... binary file data ...
------MultiPart-Mime-Boundary------
无论我做什么,仍然会得到“ 400”。 如果有人可以帮助我,我将不胜感激!那太好了! 谢谢你!