如何使用 cURL 将文件内容作为正文实体发送 [英] How to send file contents as body entity using cURL
本文介绍了如何使用 cURL 将文件内容作为正文实体发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 cURL 命令行实用程序将 HTTP POST 发送到 Web 服务.我想包含一个文件的内容作为 POST 的正文实体.我曾尝试使用 -d
以及其他带有类型信息的变体,例如 --data --data-urlencode </path/to/filename>
等等...文件总是附加的.我需要它作为身体实体.
I am using cURL command line utility to send HTTP POST to a web service. I want to include a file's contents as the body entity of the POST. I have tried using -d </path/to/filename>
as well as other variants with type info like --data </path/to/filename> --data-urlencode </path/to/filename>
etc... the file is always attached. I need it as the body entity.
推荐答案
我相信您正在寻找 @filename
语法,例如:
I believe you're looking for the @filename
syntax, e.g.:
去除新行
curl --data "@/path/to/filename" http://...
保持新行
curl --data-binary "@/path/to/filename" http://...
curl 将从文件中删除所有换行符.如果要发送带有完整换行符的文件,请使用 --data-binary
代替 --data
这篇关于如何使用 cURL 将文件内容作为正文实体发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文