3

Web.Spock.Action中的body函数应该返回原始请求正文。但是,它似乎并没有这样做:

{-# 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)

Acurl --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

4

0 回答 0