【发布时间】:2017-05-14 22:06:28
【问题描述】:
我使用了Network.Wai.Middleware.Cors 的simpleCors,它可以正常处理GET 请求,但是当我尝试发出POST 请求时,我遇到了以下问题
OPTIONS /users
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Status: 400 Bad Request 0.032443s
我能够使它工作的唯一方法是从Application.hs 的以下部分中删除simpleCors
-- | Convert our foundation to a WAI Application by calling @toWaiAppPlain@ and
-- applying some additional middlewares.
makeApplication :: App -> IO Application
makeApplication foundation = do
logWare <- makeLogWare foundation
-- Create the WAI application and apply middlewares
appPlain <- toWaiAppPlain foundation
return $ logWare $ defaultMiddlewaresNoLogging $ simpleCors $ appPlain
并添加一个 OPTIONS 方法响应
optionsNewUserR :: Handler RepPlain
optionsNewUserR = do
return $ RepPlain $ toContent ("" :: Text)
并添加 CORS 标头...但这是一个肮脏的解决方案,因为我需要更改所有 API 处理程序!非常感谢任何帮助!
【问题讨论】:
标签: rest haskell request cors yesod