我正在使用Perl访问Rest-Api:
use LWP::UserAgent; use HTTP::Request::Common; my $ua = LWP::UserAgent->new; my $req = HTTP::Request::Common::PUT("http://xxx:yyy/..."); $req->header('content-type' => 'application/json'); $req->authorization_basic('abc','xyz'); my $put_data = '{ "description" : "TestPut" }'; $req->content($put_data); my $resp = $ua->request($req); if ($resp->is_success){ print $resp->content() . "\n"; } else{ print "PUT Failed:\n"; print $resp->message . "\n"; }
但我得到一个“方法不允许”的消息.
GET工作正常.
这可能是Http-Server(Tomcat)还是防火墙的问题?
$req-> as_string:
PUT #URL Authorization: Basic xxx= Content-Type: application/json { "description" : "TestPut" }