【问题标题】:Scotty and POST paramsScotty 和 POST 参数
【发布时间】:2015-01-29 18:15:04
【问题描述】:

我现在遇到了 Scotty 网络服务器的问题 - rescue 不适用于未找到的参数 - 我仍然收到带有以下代码的 404:

post "/newsletter/create" ( do
  (param "subscriber[email]") `rescue` (\msg -> text msg)
  formContent <- param "subscriber[email]"
  text $ "found! " ++ show formContent )

我可以看到,当我只使用params 时,我的数据就在那里,并以“subscriber[email]”为索引。 [ 转义有什么问题吗?对此的任何帮助都将是巨大的。

【问题讨论】:

    标签: haskell post scotty


    【解决方案1】:

    通过一些清理,我让它工作了:

    {-# LANGUAGE OverloadedStrings #-}
    
    import Web.Scotty
    import qualified Data.Text.Lazy as TL
    
    main = scotty 3000 $ do
      post "/newsletter/create" $ do
        formContent <- (param "subscriber[email]") `rescue` (\msg -> return msg)
        text $ "found! " `TL.append` formContent
    

    我做了很多修改,但关键是rescue 被用作param 的包装,而不是更改任何内部状态,因此你不应该调用它两次。方括号没有给我带来任何麻烦。

    【讨论】:

    • 这很有意义!德普。谢谢你。我想知道param_params_ 无损功能是否是个好主意...
    • 我刚刚发现了一些对 Scotty 来说真的很糟糕的东西——如果你从一个参数中拯救出来,你就不能真正使用这个参数:rescue :: ActionM a -&gt; (Text -&gt; ActionM a) -&gt; ActionM a 如果你的处理程序是ActionM (),那么你可以' t pull 参数,因为它的类型是(),而不是Text :(
    • get 本身强制 Unit 类型:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 2019-01-31
    • 2020-03-30
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 2012-07-21
    相关资源
    最近更新 更多