27

How can I do an HTTPS request in Haskell?

For example, I want to obtain a request token via HTTPS POST from Dropbox API

P.S.: I am using Windows 8

Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272

2 Answers2

31

Thanks to packages like http-conduit, which is backed by tls, you can use simpleHttp for HTTPS.

> import Network.HTTP.Conduit
> simpleHttp "https://github.com"
...  big ugly bytestring that can be parsed in so many ways...
Uli Köhler
  • 13,012
  • 16
  • 70
  • 120
Thomas M. DuBuisson
  • 64,245
  • 7
  • 109
  • 166
5

For less dependencies, use http-client with http-client-tls:

{-# LANGUAGE OverloadedStrings #-}

import qualified Network.HTTP.Client     as H
import qualified Network.HTTP.Client.TLS as H

main :: IO ()
main = do
  httpman <- H.newManager H.tlsManagerSettings
  let req = H.setQueryString [("q", Just "r")] "https://httpbin.org/get"
  response <- H.httpLbs req httpman
  print response

(Those packages were factored out of http-conduit; if you have no need of conduit, sticking with http-client will decrease your dependency footprint.)

unhammer
  • 4,306
  • 2
  • 39
  • 52