json - Get CurlCode form cURL IO response - Haskell -


i relatively new haskell , having trouble parsing response of curl request.

here code have far:

import control.monad import network.curl import data.aeson  getreq :: urlstring -> [curloption] -> io (curlcode, string) getreq url opt = curlgetstring url opt 

when use getreq function,

prelude> getreq "http://google.com" [] 

i response:

(curlok, "<html><head><meta http-equiv="content-type" content="text/html;charset=utf-8">...) 

what trying somehow parse out curlcode (curlok). io type confused on how go getting curlcode that.

any appreciated!

here ideas of can do. of them close want do?

getcurlcode :: io (curlcode, string) -> io curlcode getcurlcode res =     (cc, _) <- res     return cc  printcurlcode :: io (curlcode, string) -> io () printcurlcode res =     (cc, _) <- res     print cc  printstatus :: io (curlcode, string) -> io () printstatus res =     cc <- getcurlcode res     if cc == curlok         putstrln "everything okay"         else putstrln "maybe not okay"  curlmessage :: curlcode -> string curlmessage cc =     case cc of         curlok -> "everything okay"         _      -> "maybe not okay"  printcurlmessage :: io (curlcode, string) -> io ()     cc <- getcurlcode res     let msg = curlmessage cc     putstrln msg 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -