加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-16 06:13:46 所属栏目:大数据 来源:网络整理
导读:我正在使用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
我正在使用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服务器可能会限制对此方法的访问.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读