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

perl – 为什么curl POST请求会崩溃我的Catalyst :: Controller

发布时间:2020-12-16 06:14:22 所属栏目:大数据 来源:网络整理
导读:我正在使用Catalyst来构建RESTful Web服务,因此我以通常的方式创建了一个Catalyst控制器 script/myapp_create.pl controller MyApp::Controller 然后我启动催化剂测试服务器 script/zoo_server.pl -rd 到目前为止一切顺利 – 我现在可以访问http:// localho
我正在使用Catalyst来构建RESTful Web服务,因此我以通常的方式创建了一个Catalyst控制器

script/myapp_create.pl controller MyApp::Controller

然后我启动催化剂测试服务器

script/zoo_server.pl -rd

到目前为止一切顺利 – 我现在可以访问http:// localhost:3000 / user并看到消息“在用户中匹配MyApp :: Controller :: User”.

然后我用下面的行替换lib / MyApp / Controller / User.pm中的第一个BEGIN行

BEGIN { extends 'Catalyst::Controller::REST' }

在做任何其他事情之前,我想检查一下我执行POST请求并观察响应的能力.所以在另一个终端窗口,我输入

curl http://localhost:3000/user --verbose --data "<test><m>whatever</m></test>" -H "Content-Type: text/xml"

此时,由于我没有实现任何POST方法,我希望看到“405 Method Not Allowed”响应.相反,我从卷曲中看到的是:

* About to connect() to localhost port 3000 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 3000 (#0)
> POST /user HTTP/1.1
> User-Agent: curl/7.19.6 (i386-apple-darwin10.0.0) libcurl/7.19.6 zlib/1.2.5
> Host: localhost:3000
> Accept: */*
> Content-Type: text/xml
> Content-Length: 28
> 
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server
* Closing connection #0

然后这似乎崩溃催化剂的测试服务器.服务器不记录任何内容,但将来尝试联系服务器,例如对“localhost:3000 / user”执行另一个GET请求,导致curl“无法连接到主机”错误.

我注意到,只有在我使用Catalyst :: Controller :: REST时才会发生这种情况.如果我只是制作一个普通的控制器,POST它就不会崩溃.所以我假设它发生在反序列化操作上,它将被委托给XML :: Simple(根据Catalyst :: Controller :: REST的默认值).有任何想法吗?

顺便说一下,我最终想做的是创建一个类似子事的方法:Local:ActionClass(‘REST’)…,以及相应的子thing_POST.我的理解是,在调用thing_POST之前,对包含XML的/ user / thing的POST请求应该自动反序列化并将其放入$c-> request->数据中.以上测试是初步的 – 旨在检查如果没有定义POST方法会发生什么. (对于它的价值,如果我创建sub thing和sub thing_POST,然后使用curl向/ user / thing发出POST请求,我会得到完全相同的行为.)

解决方法

我最终将其追溯到XML :: SAX.可重现的错误情况:

% cat >! test
<test><a>blah</a></test>
% perl -e 'use XML::SAX;my $sp = XML::SAX::ParserFactory->parser;my $tree = $sp->parse_uri("test")'
Segmentation fault

请注意,如果引用XML而不是在文件中,它可以正常工作:

% perl -e 'use XML::SAX;my $sp = XML::SAX::ParserFactory->parser;my $tree = $sp->parse_string("<a><b>test</b></a>");print $tree'
HASH(0x1009c4470)

我想我的XML :: SAX安装有问题.

(编辑:李大同)

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

    推荐文章
      热点阅读