我发送以下http请求
http://dummyServer.com/cgi-bin/swf/send.cgi?pname=PACKAGENAME&from=FROMADDRESS&to=TOADDRESS
服务器是Apache
文件:send.cgi
use CGI;
use lib '/Library/WebServer/CGI-Executables/swf/';
use My::XML qw(responce);
my $q = new CGI;
my $pname = $q->param("pname");
my $from = $q->param("from");
my $to = $q->param("to");
responce($pname, $from, $to);
文件:My / XML.pm
package My::XML;
use XML::Writer;
use Exporter qw(import);
our @EXPORT_OK = qw(responce);
my $doc = new XML::Writer(DATA_MODE => 'true', DATA_INDENT => 2);
sub responce {
my ($pname, $from, $to) = @_;
$doc->startTag("details");
$doc->dataElement( pname => "${pname}");
$doc->dataElement( from => "${from}");
$doc->dataElement( to => "${to}");
$doc->endTag();
$doc->end();
}
1;
send.cgi在cli中正常工作,获得正确的xml输出。但是当我调用上面的http请求时,我得到的是500内部服务器。我应该在浏览器窗口中显示简单的xml。
任何人都可以帮忙
答案 0 :(得分:2)
您仍需要发送正确的http标头。
print "Content-Type: text/xml\n\n";
由于你使用的是CGI
,你也可以这样输出:
print $q->header('text/xml');