我想將網頁的內容寫入文件。但是我被困在文件寫入部分。因爲它給我一個類型錯誤。如何在Haskell中編寫HTTPS請求的文件響應體?
import Control.Lens
import qualified Data.ByteString.Lazy as BL
import Network.Wreq
writeURIBodyToFile :: FilePath -> String -> IO()
writeURIBodyToFile filePath uri = do
response <- get uri
body <- (response ^. responseBody)
BL.writeFile filePath body
以下是錯誤:
Couldn't match type ‘IO BL.ByteString’ with ‘BL.ByteString’
Expected type: Getting
(IO BL.ByteString) (Response BL.ByteString) (IO BL.ByteString)
Actual type: (BL.ByteString
-> Const (IO BL.ByteString) BL.ByteString)
-> Response BL.ByteString
-> Const (IO BL.ByteString) (Response BL.ByteString)
In the second argument of ‘(^.)’, namely ‘responseBody’
In a stmt of a 'do' block: body <- (response ^. responseBody)
在此先感謝。