解决Network.HTTP'用户错误(不支持https)'

时间:2014-01-22 23:53:31

标签: haskell https

使用runghc

运行此Haskell程序时
import Network.HTTP

main = simpleHTTP (getRequest "https://stackoverflow.com")
       >>= getResponseBody >>= putStrLn

我收到错误消息

printso.hs: user error (https not supported)

我不想切换到未加密的HTTP - 如何将Network.HTTP与SSL / TLS一起使用?

1 个答案:

答案 0 :(得分:6)

您无法直接执行此操作,例如请参阅this post。但是,您可以使用http-conduit库中的Network.HTTP.Conduit代替。

首先使用cabal install http-conduit安装它。

然后您可以使用此代码(请注意,它与Network.HTTP形成对比,它使用惰性ByteString s)作为替代:

import Network.HTTP.Conduit
import qualified Data.ByteString.Lazy as LB

main = simpleHttp "https://stackoverflow.com"
       >>= LB.putStr

另一种方法是使用the Haskell libcurl binding,但这取决于原生libcurl