Perl HTTP :: Request Put – >方法不允许

前端之家收集整理的这篇文章主要介绍了Perl HTTP :: Request Put – >方法不允许前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用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"
           }

解决方法

The GET works fine. Could this be a Problem by the Http-Server (Tomcat) or a firewall?

是的,你必须看那里. GET和POST是访问网站的常用方法,而PUT通常用于REST或WebDAV,Web浏览器不使用(除非您自己执行XHR请求).因此,防火墙或HTTP服务器可能会限制对此方法的访问.

猜你在找的Perl相关文章