问题描述
我正在寻找从python API发送以下类型的POST请求:
------WebKitFormBoundarykQ0pCUTfUvTIocvw
Content-Disposition: form-data; name="filename"
SSF_nY4PQT8190207X10Showtest.gz
------WebKitFormBoundarykQ0pCUTfUvTIocvw--
请注意, SSF_nY4PQT8190207X10test.gz
不是我要发送的文件。
我要求服务器对此文件执行某些操作。
以下链接我试图通过t = s.post(url, headers=headers, files = {'filename': ('', 'content')}, verify=False)
来做到这一点
但是得到这个头
--63fb60c0045e41439442713330f821ce
Content-Disposition: form-data; name="filename"; filename=""
content
--63fb60c0045e41439442713330f821ce--
如何在请求中删除filename=""
。
在此先感谢您的帮助
1楼
尝试使用此脚本进行游戏:
#!/usr/bin/env python3
from requests import Request, Session
s = Session()
files={'filename': 'content'}
url="http://localhost"
req = Request('POST', url, files=files)
prepped = s.prepare_request(req)
print(prepped.body)
但是无论我做什么, Content_Disposition
始终具有Content-Disposition: form-data; name=""; filename=""
Content-Disposition: form-data; name=""; filename=""
Content-Disposition: form-data; name=""; filename=""
参数。
因此,我查看了请求源: : ,这使我引用了Urllib3 ,即使您提供空字符串,这些参数似乎也始终存在。
没有找到替代它们的方法。
编辑
从以上评论之一:
#!/usr/bin/env python3
from requests import Request, Session
s = Session()
files={'filename': (None,'content')}
url="http://localhost"
req = Request('POST', url, files=files)
prepped = s.prepare_request(req)
print(prepped.body)