curl的GET请求特殊字符问题

示例

curl http://x.x.x.x:9202/operating_reports/get_status?data={"operation": "get_usersuccessrate_alluser","in_args": {"condition": {}}}

curl: (3) [globbing] unmatched brace at pos 73
curl: (6) Could not resolve host: get_usersuccessrate_alluser,in_args; Unknown error
curl: (3) [globbing] unmatched brace at pos 12
curl: (3) [globbing] unmatched close brace/bracket at pos 3

curl http://127.0.0.1:8080/test?a=1&b=2&c=3

后端只能获取到参数a

原因

curl 中包含有特殊符号会导致截断 常见特殊字符 字符"+","/","?","%","#","&","="都将被转码 (字符"a-z","A-Z","0-9",".","-","_","*","" 都会直接被服务器识别,维持原值)

上面示例则是多了空格

解决办法

方式一:转义字符

curl http://x.x.x.x:9202/operating_reports/get_status?data={"operation":\ "get_usersuccessrate_alluser","in_args":\ {"condition":\ {}}}

curl http://127.0.0.1:8080/test?a=1\&b=2\&c=3

方式一:转为十六进制

特殊字符 十六进制值
% %25
# %23
& %26
+ %2B
= %3D
空格 %20
/ %2F
\ %5C
? %3F
. %2E
: %3A

注意事项

put 或者post方法中 -d 使用单引号 括起来的则不需要转义

参考链接

https://blog.csdn.net/zzq900503/article/details/91997346

本文作者:朝圣

本文链接:www.zh-noone.cn/2019/10/特殊字符

版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA 3.0许可协议。转载请注明出处!

linux内核端口设置
0 条评论