Maik
Maik

Reputation: 341

Perl HTTP::Request Put -> Method not allowed

i'm using Perl to access a 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";
}

But i am getting a "Method not allowed" Message. The GET works fine. Could this be a Problem by the Http-Server (Tomcat) or a firewall?

$req->as_string:

PUT #URL 
Authorization: Basic xxx= 
Content-Type: application/json 

{ 
           "description" : "TestPut"
           }

Upvotes: 4

Views: 855

Answers (1)

Steffen Ullrich
Steffen Ullrich

Reputation: 123270

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

Yes, you have to look there. GET and POST are the usual methods to access a web site while PUT is usually used for REST or WebDAV and not used by the web browser (unless you do your own XHR requests). Thus it might be that a firewall or HTTP server restricts access to this method.

Upvotes: 1

Related Questions