3

我一直在尝试使用这个原本简单的路由约束

Dispatch = cowboy_router:compile([{'_',
        [
            {"/tokens/:tokenid",{tokenid,int}, paytoken_handler, []}
        ]}]),

但我不断收到同样的错误。

我的请求是curl 10.10.10.56:8080/tokens/1000 -v -H "Content-Type: application/json"

[错误] 牧场侦听器 http 在 <0.97.0> 退出时使用 cowboy_protocol:start_link/4 启动了连接过程,原因是:{function_clause,[{cowboy_router,check_constraints,[{tokenid,int},[{tokenid,<<"1000 ">>}]],[{file,"src/cowboy_router.erl"},{line,276}]},{cowboy_router,match_path,4,[{file,"src/cowboy_router.erl"},{line ,264}]},{cowboy_router,execute,2,[{file,"src/cowboy_router.erl"},{line,172}]},{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol. erl"},{line,529}]}]}

注意:当我删除约束 {tokenid, int} 它工作正常。

Dispatch = cowboy_router:compile([{'_',
        [
            {"/tokens/:tokenid", paytoken_handler, []}
        ]}]),

请提供任何帮助。

谢谢。

4

1 回答 1

4

编辑

看起来约束必须作为项目列表传递

{"/:id/:h",[{id,int},{h,int}], toppage_handler, []}

对于您的情况,这应该可以

{"/tokens/:tokenid",[{tokenid,int}], paytoken_handler, []}

于 2014-01-13T12:57:29.313 回答