问题
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 ByteString
s) 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