我有一个关于 cURL 使用的简单问题。在我的 Google 搜索或手册页中没有找到太多内容来获得明确的答案。
在 here谈论使用 --data
对比 --form
关于发送文件/附件。我很想知道主要区别是什么以及在什么情况下您会选择 --data-binary
VS --form
?
POST“正文”可以通过 --data (for application/x-www-form-urlencoded)
发送或 --form (for multipart/form-data)
:
-F "foo=bar" # 'foo' value is 'bar'
-F "foo=<foovalue.txt" # the specified file is sent as plain text input
-F "foo=@foovalue.txt" # the specified file is sent as an attachment
-d "foo=bar"
-d "foo=<foovalue.txt"
-d "foo=@foovalue.txt"
-d "@entirebody.txt" # the specified file is used as the POST body
--data-binary "@binarybody.jpg"
最佳答案
HTML 4.01 Specification section on Forms 中解释了差异。 :
application/x-www-form-urlencoded is the default content type.
The content type "application/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
关于post - cURL POST --data-binary vs --form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14063311/