[Haskell-beginners] Network.HTTP basics

Daniel Fischer daniel.is.fischer at googlemail.com
Fri Apr 1 22:04:06 CEST 2011


On Friday 01 April 2011 21:42:19, Barbara Shirtcliff wrote:
> Hi, this is small, but this is the beginners list, so here goes:
> 
> I can see how to use HTTP to request a page.  for example, this works:
> 
> 
> Prelude Network.HTTP> let respgoogle = simpleHTTP $ getRequest
> "http://google.com" Prelude Network.HTTP> respgoogle
> Right HTTP/1.1 301 Moved Permanently
> Location: http://www.google.com/
> Content-Type: text/html; charset=UTF-8
> Date: Fri, 01 Apr 2011 17:31:25 GMT
> Expires: Sun, 01 May 2011 17:31:25 GMT
> Cache-Control: public, max-age=2592000
> Server: gws
> Content-Length: 219
> X-XSS-Protection: 1; mode=block
> Connection: close
> 
> that looks really nice, but hey, what if I want to see what's in the
> content?  It isn't immediately clear to me from the documentation at
> http://hackage.haskell.org/packages/archive/HTTP/4000.1.1/doc/html/Netw
> ork-HTTP.html .

stuff = do
    answer <- respgoogle
    case answer of
      Left connErr -> putStrLn "Got a connection error:" >> print connErr
      Right result -> do
            let goodies = rspBody result
            putStrLn goodies    -- or do something sensible

> 
> In the end, I'll be working with JSON, here, but I need to know how to
> get to it, and the examples in the documentation don't work (i.e. don't
> appear to be up to date).  I'm not very experienced with Haskell, so,
> it's pretty opaque.
> 
> Thanks,
> Bar
> 



More information about the Beginners mailing list