【问题标题】:cURL POST --data-binary vs --formcURL POST --data-binary vs --form
【发布时间】:2012-12-28 01:03:58
【问题描述】:

我有一个关于 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"

【问题讨论】:

    标签: post curl


    【解决方案1】:

    HTML 4.01 Specification section on Forms中解释了区别:

    application/x-www-form-urlencoded 是默认的内容类型。

    内容类型“application/x-www-form-urlencoded”对于发送大量二进制数据或包含非 ASCII 字符的文本效率低下。内容类型“multipart/form-data”应用于提交包含文件、非 ASCII 数据和二进制数据的表单。

    【讨论】:

    • 如果 content-type 被指定为“multipart/form-data”,但是当使用 curl 时,它们以 --data-binary 的形式发送它会失败吗?
    【解决方案2】:

    这正是主要区别,发送到服务器的数据类型(application/x-www-form-urlencodedmultipart/form-data

    【讨论】:

    • 谢谢!您将使用这两种数据的场景是什么?所以form-urlencoded是把数据嵌入到请求中,但是multipart不一样?
    猜你喜欢
    • 2015-09-19
    • 2015-01-16
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2016-01-22
    • 2015-10-28
    相关资源
    最近更新 更多