【问题标题】:How do you use reqGetParams (Yesod) properly?您如何正确使用 reqGetParams (Yesod)?
【发布时间】:2013-07-12 17:31:17
【问题描述】:
{-# 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"

我做错了什么?谢谢!

【问题讨论】:

  • curl --data 将通过 POST 发送参数,而 reqGetParams 将为您提供在 URL 中传递的参数;即“localhost:3000?foo=bar”。不过,我对 Yesod 还不够熟悉,无法告诉您如何访问 POST 数据。

标签: haskell yesod


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-12-06
    • 1970-01-01
    • 2018-07-28
    • 2014-04-19
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2012-04-04
    • 2023-03-07
    相关资源
    最近更新 更多