Uli Köhler
Uli Köhler

Reputation: 13751

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

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?

Upvotes: 5

Views: 828

Answers (1)

Uli Köhler
Uli Köhler

Reputation: 13751

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.

Upvotes: 7

Related Questions