views:

61

answers:

1

Is there a way to make https calls with the Network.Browser package. I'm not seeing it in the documentation on Hackage.
If there isn't a way to do it with browse is there another way to fetch https pages?

My current test code is

import Network.HTTP
import Network.URI (parseURI)
import Network.HTTP.Proxy
import Data.Maybe (fromJust)
import Control.Applicative ((<$>))
import Network.Browser

retrieveUrl :: String -> IO String
retrieveUrl url = do
  rsp <- browse $ request (Request (fromJust uri) POST [] "Body")
  return $ snd (rspBody <$> rsp)
  where uri = parseURI url

I've been running nc -l -p 8000 and watching the output. I see that it doesn't encrypt it when I do retrieveUrl https://localhost:8000

Also when I try a real https site I get:

Network.Browser.request: Error raised ErrorClosed
*** Exception: user error (Network.Browser.request: Error raised ErrorClosed)

Edit: Network.Curl solution (For doing a SOAP call)

import Network.Curl (curlGetString)
import Network.Curl.Opts

soapHeader s = CurlHttpHeaders ["Content-Type: text/xml", "SOAPAction: " ++ s]
proxy        = CurlProxy "proxy.foo.org"
envelope     = "myRequestEnvelope.xml"

headers  = readFile envelope >>= (\x -> return [ soapHeader "myAction"
                                               , proxy
                                               , CurlPost True
                                               , CurlPostFields [x]]) 

main = headers >>= curlGetString "https://service.endpoint"
+2  A: 

I've wondered about this in the past and have always ended up just using the libcurl bindings. It would be nice to have a more Haskelly solution, but Network.Curl is very convenient.

Travis Brown
Yeah, I ended up going with Network.Curl based on your suggestion, thanks for the help.
devrand