使用 CURL 我可以发布一个文件
CURL -X POST -d "pxeconfig=`cat boot.txt`" https://ip:8443/tftp/syslinux
我的文件看起来像
$ cat boot.txt
line 1
line 2
line 3
我正在尝试使用 python 中的 请求 模块来实现同样的事情
r=requests.post(url, files={'pxeconfig': open('boot.txt','rb')})
当我在服务器端打开文件时,文件包含
{:filename=>"boot.txt", :type=>nil, :name=>"pxeconfig",
:tempfile=>#<Tempfile:/tmp/RackMultipart20170405-19742-1cylrpm.txt>,
:head=>"Content-Disposition: form-data; name=\"pxeconfig\";
filename=\"boot.txt\"\r\n"}
请建议我如何实现这一目标。
原文由 user1191140 发布,翻译遵循 CC BY-SA 4.0 许可协议
您的 curl 请求将文件内容作为表单数据发送,而不是实际文件!你可能想要类似的东西