shell curl 数据中含有空格 如何提交

No Comments IT必备工具

 

如果提交内空带 空格 提交会报错

"msg":"ddddddddddddddddddddddddddd dddddddddddd dddddddddddddd dddddddddd dddddddd"}

curl: (6) Could not resolve host: dddddddddddd; Unknown error
curl: (6) Could not resolve host: dddddddddddddd; Unknown error
curl: (6) Could not resolve host: dddddddddd; Unknown error
curl: (3) [globbing] unmatched close brace/bracket at pos 10

 

解决方案1

 

去掉空格,或用%20等替换

------中间广告---------

 

将这些字符转化成服务器可以识别的字符,对应关系如下:
URL字符转义

用其它字符替代吧,或用全角的。

+    URL 中+号表示空格                                 %2B   
空格 URL中的空格可以用+号或者编码           %20 
/   分隔目录和子目录                                     %2F     
?    分隔实际的URL和参数                             %3F     
%    指定特殊字符                                          %25     
#    表示书签                                                  %23     
&    URL 中指定的参数间的分隔符                  %26     
=    URL 中指定参数的值                                %3D

 

方案2.

最重要的来了, “$data”  要加双引号

curl -H "Content-Type:application/json" -X POST -d "$data" $url

发表评论