5

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 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

can you suggest how can I put filter on this stream. I want to find some text from this String...
@Manvi I think you could use conduit's sink to get an IO Text or something like that, and then use standard filters for String or Text, see e.g. this tutorial: schoolofhaskell.com/school/to-infinity-and-beyond/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.