【问题标题】:Mojolicious API is disregarding the characters after " . " in the URL argumentMojolicious API 忽略 URL 参数中“.”之后的字符
【发布时间】:2021-10-31 09:11:02
【问题描述】:

我在我的代码中定义了以下路线:

my $route = $r->any('/api')->to('API#');
$route->get('/get_data/:filename')->to('#submit_forms');

如果我传递到 url 的文件名是“foo123456.bar_baz.bz2”,当我打印参数时,我得到:(例如http://example.com/api/get_data/foo123456.bar_baz.bz2

print Dumper($c->param('filename'));
# foo123456

为什么会在月经结束后剪掉所有东西?

【问题讨论】:

  • 从 API 的角度来看,按名称请求文件而不是请求特定格式的特定数据集似乎很奇怪。

标签: api perl mojolicious


【解决方案1】:

使用#(或*)代替:作为占位符:

$route->get('/get_data/#filename')->to('#submit_forms');

Mojolicious 有 3 种占位符:

引用宽松占位符的文档:

它们对于手动匹配文件名和扩展名特别有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-08
    • 2011-01-29
    • 2023-01-18
    • 2019-10-17
    • 2017-01-11
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多