gpt4 book ai didi

curl - cURL 可以编码等于 (=) 符号吗?

转载 作者:行者123 更新时间:2023-12-03 19:58:13 27 4
gpt4 key购买 nike

我知道 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=\""

关于curl - cURL 可以编码等于 (=) 符号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29238479/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com