2

首先我会给你代码,然后是错误,然后是一些类型信息。问题是:我怎样才能弄清楚发生了什么?我该如何解决这个问题?

readTask = do
   req' <-  parseUrl "https://10.64.251.32/rest/api/latest/issue/BNAP-291"
   manager <- newManager manSettings
   let req'' = applyBasicAuth (pack "sandboxer") (pack "sandboxer") req'
   Response _ _ _ body <-runResourceT $ http req'' manager 
   pBody <- runResourceT $
            body $$+- sinkParser json

   --   print pBody
   --   closeManager manager

   return ()
      where manSettings =
               def
                 { managerCheckCerts = \ _ _ -> return CertificateUsageAccept }

这编译得很好。这是我运行编译后的代码时发生的情况

dist/build/Spike/Spike
Spike: <socket: 3>: hGetBuf: illegal operation (handle is closed)

body是以下类型

Data.Conduit.Internal.ResumableSource
(Control.Monad.Trans.Resource.ResourceT IO)
Data.ByteString.Internal.ByteString

感谢反馈,我不知道如何开始解决此问题。

4

1 回答 1

1

第一个runResourceT调用是在解析主体之前关闭套接字。您需要将这两个runResourceT调用合二为一。ResourceT是一个Monad实例,因此您可以do在解析完成后使用符号和一些小手术来释放套接字:

readTask = do
   req' <-  parseUrl "https://10.64.251.32/rest/api/latest/issue/BNAP-291"
   manager <- newManager manSettings
   let req'' = applyBasicAuth (pack "sandboxer") (pack "sandboxer") req'
   runResourceT $ do
      Response _ _ _ body <- http req'' manager 
      pBody <- body $$+- sinkParser json
      liftIO $ print pBody

   closeManager manager

   return ()
      where manSettings =
               def
                 { managerCheckCerts = \ _ _ -> return CertificateUsageAccept }
于 2012-11-08T20:34:33.557 回答