如何从Perl CGI脚本调用curl? [英] How can I call curl from a Perl CGI script?

查看:182
本文介绍了如何从Perl CGI脚本调用curl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CGI(perl)脚本,正在尝试使用打开命令调用curl:

I have a CGI (perl) script that is attempting to call curl using the open command:

@curl = ('/usr/bin/curl', '-S','-v','--location', $url, 
                          '-H', 'Content-Type:'.$content_type,
                          '-H', "Authorization: $authorization",
                          '-H', "X-Gdata-Key:$gdata_key",
                          '-H', "Content-Length:$content_length",
                          '-H','GData-Version:2',
                          '--data',"\@$filename");

然后像这样执行:

open CURL, "-|", @curl;

该程序可从命令行完美运行,但是当我尝试在浏览器中运行时,页面最终超时。

The program works perfectly from the command line, but when I try to run it in the browser, the page ends up timing out.

我需要在服务器或脚本中进行哪些更改才能使其正常运行?

What do I need to change on my server or in my script to get this to work properly?

推荐答案

在查看错误日志并看到错误后

After looking at the error log and seeing the error

[Mon Nov 30 14:59:07 2009] [error] slurp_filename(
'/var/www/vhosts/mydomain.net/httpdocs /youtube/youtube.pl') / opening: (2)
No such file or directory at /usr/lib64/perl5/vendor_perl/5.8.6/
x86_64-linux-thread-multi/ModPerl/RegistryCooker.pm line 540 

我认为这与我将XML传递为文件而不是字符串进行卷曲有关。以下是新命令,它与以字符串形式传递的xml一起使用:

I thought it had something to do with the fact that I'm passing in my XML to curl as a file instead of as a string. Here is the new command that works with the xml passed as a string instead:

@curl = ('/usr/bin/curl', '-S','-v','--location', $url, '-H',
'Content-Type:'.$content_type,'-H',"Authorization: $authorization",'-H',
"X-Gdata-Key:$gdata_key",'-H',"Content-Length:$content_length",'-H',
'GData-Version:2','--data',"$xml");

而且我仍在使用以下命令打开/调用curl:

And I am still using the command below to open/call curl:

open CURL, "-|", @curl;

它现在可以在浏览器中成功运行,并向我返回我要求使用的值。

It now runs successfully in the browser and returns me the values I am requesting with it.

这篇关于如何从Perl CGI脚本调用curl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆