windows 如何在 curl.exe 的 -d 参数中发送双引号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4514199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send double quote in -d parameter for curl.exe?
提问by slolife
How can I send a double quote char using curl.exe in the -d
parameter. I don't want to URL encode the double quote. Since the -d
data needs to be surrounded in double quotes, I cannot seem to get it to work.
如何在-d
参数中使用 curl.exe 发送双引号字符。我不想对双引号进行 URL 编码。由于-d
数据需要用双引号括起来,我似乎无法让它工作。
Or is there another flag for curl.exe that tells it to use a files contents for the whole form post data?
或者 curl.exe 是否有另一个标志告诉它对整个表单发布数据使用文件内容?
采纳答案by martona
You can most certainly escape double quotes. How you do that depends on your operating system and shell, which you fail to specify. On Windows, you'd use the ^ as the escape character.
您肯定可以转义双引号。你如何做到这一点取决于你的操作系统和外壳,你没有指定。在 Windows 上,您可以使用 ^ 作为转义字符。
You can also do this:
你也可以这样做:
curl [...] -d @filename
...which reads post data from a file called filename.
...从名为 filename 的文件中读取发布数据。
Google and/or man is your friend.
谷歌和/或人是你的朋友。
回答by Alexander Chuprin
My curl.exe
works with this form:
我curl.exe
使用这种形式的作品:
-d "{\"param\":\"value\"}"
i.e. doublequotes around data, and doublequotes masked with backslash inside
即数据周围的双引号,以及内部用反斜杠屏蔽的双引号
回答by Isac
You can surround the data with single quotes and use double quotes inside.
您可以用单引号将数据括起来并在里面使用双引号。
回答by Gaz
For the escaping of double quote question, I'm finding that tripling the doublequotes works from the shell:
对于双引号问题的转义,我发现从 shell 中将双引号增加三倍:
curl -d {"""foo""":"""bar"""}
while doubling the doublequotes works from within a batch file:
在批处理文件中加倍双引号时:
curl -d {""foo"":""bar""}
Which is quite annoying for testing in the shell first.
首先在 shell 中进行测试是很烦人的。
回答by Anand Rockzz
There is something called dollar slashy string.
有一种叫做美元斜线的东西。
def cmd = $/ curl -d '{"param":"value"}' -X POST https://example.com/service /$
sh cmd