1
{-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-}
{-# LANGUAGE MultiParamTypeClasses, TypeFamilies #-}

import Yesod
import Control.Monad (void)

data Foo = Foo

mkYesod "Foo" [parseRoutes|
    / FooR POST
|]

instance Yesod Foo

-- Always prints "".
postFooR = void $
    getRequest >>= liftIO . print . ("Params :" ++) . concatMap show . reqGetParams

main = warp 3000 Foo

我正在学习一些 Yesod 教程,但我一直在尝试检查 POST 参数。这是我运行上述代码时发生的情况:

$ runhaskell foo.hs
$ curl --data "foo=bar" localhost:3000

14/Jul/2013:15:01:51 -0700 [Info#yesod-core] Application launched @(yesod-core-1.2.3:Yesod.Core.Dispatch ./Yesod/Core/Dispatch.hs:129:11)
"Params: "
127.0.0.1 - - [14/Jul/2013:15:02:07 -0700] "POST / HTTP/1.1" 200 - "" "curl/7.30.0"

我究竟做错了什么?谢谢!

4

1 回答 1

1

我认为您正在寻找的功能是runRequestBody.

于 2013-07-16T04:01:29.510 回答