当我尝试在支持 perl 的 Web 服务器中运行以下代码时,出现 500 内部服务器错误:
#! /usr/bin/perl
use LWP;
my $ua = LWP::UserAgent->new;
$ua->agent("TestApp/0.1 ");
$ua->env_proxy();
my $req = HTTP::Request->new(POST => 'http://www.google.com/loc/json');
$req->content_type('application/jsonrequest');
$req->content('{ "cell_towers": [{"location_area_code": "55000", "mobile_network_code": "95", "cell_id": "20491", "mobile_country_code": "404"}], "version": "1.1.0", "request_address": "true"}');
my $res = $ua->request($req);
if ($res->is_success) {
print $res->content,"\n";
} else {
print $res->status_line, "\n";
return undef;
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行下面的代码时没有错误:
#! /usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Hello World!</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H2>Hello World!</H2> <br /> \n";
foreach $key (sort keys(%ENV)) {
print "$key = $ENV{$key}<p>" ;
}
print "</BODY>\n";
print "</HTML>\n";
Run Code Online (Sandbox Code Playgroud)
所以我认为我的代码有一些问题。当我使用 -wc 命令在本地计算机中运行第一个 perl 脚本时,它表示语法正确。请帮帮我。
我假设您正在将第一个脚本作为 CGI 脚本运行?您需要包含内容类型:
print "Content-type: text/plain\n\n";
Run Code Online (Sandbox Code Playgroud)
在任何其他输出之前(当然,更改text/plain为或任何适当的内容!)text/html
| 归档时间: |
|
| 查看次数: |
12535 次 |
| 最近记录: |