
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/Network-H... . 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

On Fri, Apr 1, 2011 at 2:42 PM, Barbara Shirtcliff
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/Network-H... .
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.
Hi, The Response type is exported non-abstractly by the HTTP package, with documentation here: http://hackage.haskell.org/packages/archive/HTTP/4000.1.1/doc/html/Network-H... You can either pattern-match on the response, or use the rspBody function to extract the response body. Take care, Antoine

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
participants (3)
-
Antoine Latter
-
Barbara Shirtcliff
-
Daniel Fischer