cURL 可以编码等号 (=) 吗?

Can cURL encode equals (=) sign?

我知道 cURL 可以做这样的事情:

curl -v "http://localhost:30001/data" --data-urlencode "msg=hello world"

...但是如果我的 "msg" 包含等号 (=) 怎么办?

curl -v "http://localhost:8080/data" --data-urlencode "msg=hello=&msg2=hello2=" --trace-ascii /dev/stdout

这导致 msg=hello%3D%26msg2%3Dhello2%3D

有没有一种方法 cURL 可以在不求助于 Python 或其他方法(这是我当前的解决方案)的情况下对其进行编码?我希望有一个特定于 cURL 的解决方案,因此使用正则表达式或其他东西替换“=”并不理想。

它应该能够……也许不能……来自 curl 网站:

--data-urlencode

(HTTP) This posts data, similar to the other --data options with the exception that this performs URL-encoding. (Added in 7.18.0)

To be CGI-compliant, the part should begin with a name followed by a separator and a content specification. The part can be passed to curl using one of the following syntaxes:

content

This will make curl URL-encode the content and pass that on. Just be careful so that the content doesn't contain any = or @ symbols, as that will then make the syntax match one of the other cases below!

Source

根据您发送的位置,如果内容包含 =@ 符号,您可以将其作为 XML 或 JSON 发送:

curl -v "http://localhost:30001/data" -H Content-Type:"application/xml" -d '<comments comments="30DAYCC 1ST 2ND 07 000001.00 Test notes"/>'

要指定数据应作为 POST 数据发送,请使用 -X 选项以及 POST

curl -v -X POST "http://localhost:30001/data" -H Content-Type:"application/xml" -d '<comments comments="30DAYCC 1ST 2ND 07 000001.00 Test notes"/>'

除此之外,我认为您必须事先使用一些东西对数据进行编码。

编辑:抱歉,如果我的 xml 无效 xml。我通常不会写出我的 xml,所以是的。

如果您想按照示例中的方式发送,请尝试在消息部分加上引号。

curl -v "http://localhost:30001/data" --data-urlencode "msg=\"hello=\""