perl – 使用curl发布Gzip数据
发布时间:2020-12-16 06:19:09 所属栏目:大数据 来源:网络整理
导读:即时尝试使用系统curl将gzip压缩数据发布到服务器,但我总是遇到奇怪的错误 `curl -sS -X POST -H "Content-Type: application/gzip" --data-binary $data $url` 给 curl: no URL specified! 和 `curl -sS -X POST -H "Content-Type: application/gzip" --dat
即时尝试使用系统curl将gzip压缩数据发布到服务器,但我总是遇到奇怪的错误
`curl -sS -X POST -H "Content-Type: application/gzip" --data-binary $data $url` 给 curl: no URL specified! 和 `curl -sS -X POST -H "Content-Type: application/gzip" --data-binary "$data" $url` 给 sh: -c: line 0: unexpected EOF while looking for matching `"' sh: -c: line 1: syntax error: unexpected end of file 解决方法
添加“是朝着正确方向迈出的一步,但您没有考虑$data可能包含”,$等.您可以使用
String::ShellQuote来解决问题.
use String::ShellQuote qw( shell_quote ); my $cmd = shell_quote( curl => ( '-sS','-X' => 'POST','-H' => 'Content-Type: application/gzip','--data-binary' => $data,$url,),); my $output = `$cmd`; 或者你可以完全避开外壳. my @cmd = ( curl => ( '-sS',); open(my $pipe,'-|',@cmd) or die $!; my $output = do { local $/; <$pipe> }; close($pipe); 或者,如果您实际上不需要捕获输出,则以下内容也完全避免了shell: system( curl => ( '-sS',); 也就是说,我不知道你怎么可能发送包含NUL字节的字符串,这可能是一个gzip压缩文件.我认为你的做法本质上是有缺陷的. 你知道libcurl(卷曲的胆量)可以通过Net::Curl::Easy访问吗? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |