Resolving Network.HTTP 'user error (https not supported)'

时光总嘲笑我的痴心妄想 提交于 2021-02-09 02:40:26

问题


When running this Haskell program using runghc:

import Network.HTTP

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

I get the error message

printso.hs: user error (https not supported)

I don't want to switch to unencrypted HTTP -- how can I use Network.HTTP with SSL/TLS?


回答1:


You can't do that directly, see for example this post. However you could use Network.HTTP.Conduit from the http-conduit library instead.

First install it using cabal install http-conduit.

Then you can use this code (note that it contrast to Network.HTTP it uses lazy ByteStrings) as a replacement:

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

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

Another alternative is to use the Haskell libcurl binding which depends on the native libcurl, however.



来源:https://stackoverflow.com/questions/21296606/resolving-network-http-user-error-https-not-supported

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!