【问题标题】:Cant write http request headers to file in perl无法将http请求标头写入perl中的文件
【发布时间】:2013-10-01 02:52:06
【问题描述】:

我正在尝试将请求中的 http 标头写入文件。 单独执行的 perl 脚本运行良好并写入文件。但是当我从 http 请求调用脚本时,我收到 http 500 错误并且错误日志说..'无法打开文件' 我评论了脚本中的“打开文件”行,当从浏览器调用时它工作得很好。请告诉我我在这里做错了什么? 下面是代码:

#!/usr/bin/perl  
use CGI qw(:standard); 
use strict; 
use warnings; 
use Carp; 
use LWP::Simple; 
my $query = CGI->new; 
my $file = '/home/suresh/clientrequest.txt'; 
chmod 644, $file; 
sleep(1); 
open my $flh, '+>>', "$file" or die "Cannot open file"; 
$flh->autoflush(); 
# Read the data here 
print $flh my @keywords = $query->keywords; 
print $flh $query->header(-domain=>'testdomain'); 
print $flh my @names= $query->param; 
close $flh; 
print header; 
print start_html("Welcome"); 
print $ENV{QUERY_STRING}; 
print end_html;

【问题讨论】:

    标签: perl http apache2 cgi


    【解决方案1】:

    apache 用户没有对该文件的写入权限。

    要获得更好的错误消息,请更改此行:

    open my $flh, '+>>', "$file" or die "Cannot open file"; 
    

    open my $flh, '+>>', "$file" or die "Cannot open file '$file': $!"; 
    

    【讨论】:

    • 谢谢M42,你说得对,apache用户没有写权限,我把文件权限改成777就可以了。
    猜你喜欢
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    相关资源
    最近更新 更多