牛仔'GET'请求变量值

时间:2013-11-18 09:03:41

标签: erlang cowboy

请告诉我,如何获取GET请求的变量值 我这样做了:

{Method, Req2}       = cowboy_req:method(Req),
{FwdIPRaw, Req3}     = cowboy_req:header(<<"x-forwarded-for">>, Req2),
{ClientCookie, Req4} = cowboy_req:cookie(<<"cook">>, Req3),
{ok, GetVals, Req5}  = cowboy_req:qs_vals(Req4),
MessageId   = proplists:get_value(<<"mid">>, GetVals),
EchoName    = proplists:get_value(<<"m">>, GetVals),
{ok, Req5, State}.

但我收到错误:qs_vals - undefined

1 个答案:

答案 0 :(得分:1)

对于当前牛仔版本(0.9.0)documentation sayscowboy_req:qs_vals(Req4)返回{QsVals, Req5},其中QsVals可以是[](空列表)。 所以尝试0.9.0牛仔版并修复{ok, GetVals, Req5} = cowboy_req:qs_vals(Req4){GetVals, Req5} = cowboy_req:qs_vals(Req4)