如何知道从服务器端的 rest 客户端调用了哪个 http 操作

how to know which http action called from rest client at server side

当通过 LWP 或 REST::Client 或 HTTP::Request 等 rest 客户端向服务器发出请求(如 GET POST PATCH 等操作)时。我们如何解码请求,以便我们将获得从客户端调用的实际方法。如果我们能够获得相应的操作,我们将相应地处理或回复客户。

通过这种方式我可以获得 headers,在 post 请求中发送的所有参数。

my $q = CGI->new;
my $input = $q->param( 'POSTDATA' ); # for content

my %headers = map { $_ => $q->http($_) } $q->http();

print $q->header('text/plain');
print "Got the following headers:\n";
    for my $header ( keys %headers ) {
        print "$header: $headers{$header}\n";
    }

现在我的问题是如何接收像 GET 或 POST 这样的操作。

来自the docs

request_method()
Returns the method used to access your script, usually one of 'POST', 'GET' or 'HEAD'.


同样来自文档:

CGI.pm is no longer considered good practice for developing web applications, including quick prototyping and small web scripts. There are far better, cleaner, quicker, easier, safer, more scalable, more extensible, more modern alternatives available at this point in time. These will be documented with CGI::Alternatives.