Я написал программу CGI и отправляю клиенту ошибку состояния с заголовком HTTP. но когда я попытался использовать mod_perl, он ответил только со статусом 200 ok. Как я могу отправить собственный код состояния?
вот код, когда я хочу ответить ошибкой пользовательского статуса:
my $cgi = new CGI;
print $cgi->header(-type=>"text/html", -charset=>'utf-8', -status=>599);
EDIT:
вот код:
#!/usr/bin/perl -w
use strict;
use warnings;
use CGI;
use SessionManagement;
my $cgi = new CGI;
my $method = $cgi->param("method");
my $sessionManagement = new SessionManagement(cgi=>$cgi);
if($sessionManagement){
if (defined($method)) {
if($method eq "authentication") {
loginMethod($cgi,$sessionManagement);
} elsif ($method eq "someMethod"){
someMethod($cgi);
} else{
print $cgi->header(-type=>"text/xml", -charset=>'utf-8');
print "<html>method does not exist</html>";
}
} else {
print $cgi->header(-type=>"text/html", -charset=>'utf-8' , -status=>599);
print "<html>blah blah</html>";
}
}else{
print $cgi->header(-type=>"text/html", -charset=>'utf-8' , -status=>599);
print "<html>blah blah</html>";
}
-------------------------------------------
ИЗМЕНИТЬ 2
предоставление дополнительной информации: когда я использую команду curl -v 192.168.1.212/mymodperl/test.pl
в оболочке.
вот ответ:
* About to connect() to 192.168.1.212 port 80 (#0)
* Trying 192.168.1.212... connected
* Connected to 192.168.1.212 (192.168.1.212) port 80 (#0)
> GET /mymodperl/test.pl HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.1.212
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sat, 25 Nov 2017 11:04:18 GMT
< Server: Apache/2.2.15 (Red Hat)
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=ISO-8859-1
<
<html>hi</html><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
root@localhost and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at 192.168.1.212 Port 80</address>
</body></html>
* Closing connection #0
curl -v <url>
для того, где вы ожидаете код 599, и опубликовать вывод, который вы получили в своем вопросе? Статус - это первое, что должно вернуться, и я предполагаю, что это может быть случай ошибки порядка заголовка. - person Tarun Lalwani   schedule 25.11.2017$cgi->$header->status('599 Some Issue');
перед печатью или настройкой любого заголовка - person Tarun Lalwani   schedule 25.11.2017curl
. - person Sarah Aziziyan   schedule 25.11.2017Apache/2.4.18
, может быть это из-за более старой версии apache? Можешь попробовать с последней? - person Tarun Lalwani   schedule 25.11.2017