简体   繁体   中英

How i can handle http requests in perl?

I tried to use CGI.pm (3.15), but it can't handle PUT requests.

I'm building a REST API, so I need methods PUT, GET, POST and DELETE.

Any ideas?

Code:

#!/usr/bin/perl

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);

main: {

print "Content-Type: text/html; charset=utf-8\n\n";

my $query = CGI->new;
my $value1 = $query->param('param1');
my $value2 = $query->param('param2');

my $data = $query->param('PUTDATA');

print "value1[$value1] value2[$value2] data[$data]\n";
};

Curl :

curl 'http://localhost/cgi-bin/testing.cgi' -X PUT -H 'Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo' -H 'Accept-Encoding: gzip,deflate,sdch' -H 'Host: 192.168.8.197' -H 'Accept-Language: es-419,es;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: */*' -H 'Connection: keep-alive' --data 'param1=hola&param2=hola' --compressed

value1, value2 and data always empty.

I found it!

The solution was doing an update to the perl module CGI to 3.63 and now works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM