perl - 为什么 curl POST 请求会使我的 Catalyst::Controller::REST Controller 崩溃?

标签 perl rest curl http-post catalyst

我正在使用 Catalyst 构建一个 RESTful Web 服务,所以我以通常的方式创建了一个 Catalyst Controller

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”响应。相反,我从 curl 看到的是:
* 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 时才会发生这种情况。如果我只是制作一个常规 Controller ,那么发布到它不会导致任何崩溃。所以我假设它发生在反序列化操作上,该操作将委托(delegate)给 XML::Simple(根据 Catalyst::Controller::REST 的默认设置)。有任何想法吗?

顺便说一句,我最终想要做的是创建一个像 sub thing :Local :ActionClass('REST') ... 这样的方法。 ,以及相应的 sub thing_POST .我的理解是,对包含 XML 的/user/thing 的 POST 请求应该会自动反序列化并将其放入 $c->request->data。 , 在 thing_POST 之前叫做。上述测试是对此的初步测试 - 旨在检查如果未定义 POST 方法会发生什么。 (对于它的值(value),如果我创建 sub thingsub 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 安装有问题。

关于perl - 为什么 curl POST 请求会使我的 Catalyst::Controller::REST Controller 崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5987810/

相关文章:

html - Paypal 订阅设置

php - 无法通过 HTTPS 获取 file_get_contents 或 cURL

regex - grep 通过彩色文本,例如海湾合作委员会 | colorgcc |正则表达式

linux - 文件大小超过 60K 时文件上传失败

perl - 使用 perl 将\x3c/div\x3e 转换为 <div>

c# - 如何使用 C# WCF RESTful(即 Web)服务发送 CSV 文件?

r - 在 RCurl 中创建 C 级文件句柄,用于写入下载的文件

php - PHP 中的 scandir() 太慢了

java - 我正在尝试使用 HTTPClient 发出简单的身份验证请求,但收到错误

java - 仅在 REST API 调用时出现 Spring Boot 404