微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何检查/调试仆人-客户请求的正文?

如何解决如何检查/调试仆人-客户请求的正文?

此处提供完整的最小示例项目: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
}

虽然我希望一个身体出现一些文字。我期望这样的原因-因为如果将请求发送到服务器并进行调试/检查-我的确看到带有文本的正文。所以我在这里的问题是,为什么仆人说rawBodyFalse,我该如何实际显示它?

实际发送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 举报,一经查实,本站将立刻删除。