body中的Web.Spock.Action函数应该返回原始请求正文。但是,它似乎并没有这样做:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text.Encoding (decodeUtf8)
import Debug.Trace (trace)
import Web.Spock
import Web.Spock.Config
app :: SpockM () () () ()
app = do
get root $ text "Hello!"
post "test" $ do
b <- body -- b is always ""!
text $ trace ("b="++show b) decodeUtf8 b
main :: IO ()
main = do
spockCfg <- defaultSpockCfg () PCNoDatabase ()
runSpock 3000 (spock spockCfg app)
curl --data 123123 localhost:3000/test
不返回任何内容,trace
输出确认b
为空字符串。
Spock is running on port 3000
b=""
等效的Scotty应用可以正常运行:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text.Lazy.Encoding (decodeUtf8)
import Web.Scotty
main = scotty 3000 $ do
get "/" $ text "Hello!"
post "/test" $ do
b <- body -- works fine
text $ decodeUtf8 b
我绝对看不出我做错了什么。任何意见都将受到高度赞赏!
更新:以上示例适用于Spock >= 0.12.0.0
!