问题描述
此处提供完整的最小示例项目:https://github.com/chrissound/217
我已阅读https://docs.servant.dev/en/v0.16/cookbook/using-free-client/UsingFreeClient.html
我最后得到的地方:
type API = "square"
:> Capture "n" Int
:> ReqBody '[JSON] ClientInfo
:> Get '[JSON] Int
api :: Proxy API
api = Proxy
myapitest = I.client api
getSquare :: Int -> ClientInfo -> Free ClientF Int
getSquare = Servant.Client.Free.client api
test :: IO ()
test = case getSquare 12 (ClientInfo "" "" 123 []) of
Pure n ->
putStrLn $ "ERROR: got pure result: " ++ show n
Free (Throw err) ->
putStrLn $ "ERROR: got error right away: " ++ show err
Free (RunRequest req k) -> do
burl <- parseBaseUrl "http://localhost:8000"
mgr <- HTTP.newManager HTTP.defaultManagerSettings
let req' = I.requestToClientRequest burl req
putStrLn $ "Making request: " ++ show req'
Making request: Request {
host = "localhost"
port = 8000
secure = False
requestHeaders = [("Accept","application/json;charset=utf-8,application/json"),("Content-Type","application/json;charset=utf-8")]
path = "/square/12"
queryString = ""
method = "GET"
proxy = nothing
rawBody = False
redirectCount = 10
responseTimeout = ResponseTimeoutDefault
requestVersion = HTTP/1.1
}
虽然我希望一个身体出现一些文字。我期望这样的原因-因为如果将请求发送到服务器并进行调试/检查-我的确看到带有文本的正文。所以我在这里的问题是,为什么仆人说rawBody
是False
,我该如何实际显示它?
实际发送HTTP请求的非调试代码为:
main :: IO ()
main = do
putStrLn "Hello,Haskell!"
run
test
queries = myapitest 10 (ClientInfo "" "" 123 [])
run :: IO ()
run = do
manager' <- newManager defaultManagerSettings
res <- runclientM queries (mkClientEnv manager' (BaseUrl Http "localhost" 8000 ""))
case res of
Right (message) -> do
pprint message
Left err -> do
putStrLn $ "Error: "
pprint err
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)