Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Curl 旋度能编码等号吗?_Curl_Urlencode_Url Encoding - Fatal编程技术网

Curl 旋度能编码等号吗?

Curl 旋度能编码等号吗?,curl,urlencode,url-encoding,Curl,Urlencode,Url Encoding,我知道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可以做这样的事情:

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


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

它应该能够。。。也许不是。。。从curl网站:

--数据编码

(HTTP)该选项发布数据,与其他--data选项类似,只是执行URL编码。(在7.18.0中添加)

为了与CGI兼容,部件应该以名称开头,后跟分隔符和内容规范。可以使用以下语法之一将零件传递给curl:

内容

这将使curl URL对内容进行编码并将其传递注意不要让内容包含任何=或@符号,因为这样会使语法与下面的其他情况匹配

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

curl -v "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=\""

您的第二个示例编码得很好。它发送数据
msg=hello%3D
@Phylogenesis你说得对!我修改了我的例子,以更准确地反映一个失败的例子。谢谢你指出这一点。
curl--data urlencode“msg=hello=“--data urlencode”msg2=hello2=“
执行您想要的操作。如果我能保证服务器了解如何将XML或JSON解析为POST数据,我想这可能会起作用。。。非常好的一点,包括来自cURL站点的部分,我不知道..@aikeru您应该能够检查服务器响应头以查看它们期望的数据。很可能他们需要url编码的数据,但即使如此,如果您在请求头中指定内容类型为xml或json,服务器可能也会接受它。至少我这样做运气不错。您可以指定数据也应用作post数据。我将更新我的答案。您的示例的问题是它们都是无效的xml。@Phylogenesis,这是因为它们都是示例。。我通常不写我的xml,所以我的不好。我会更新的,哈哈
curl -v "http://localhost:30001/data" --data-urlencode "msg=\"hello=\""