Skip to content

Instantly share code, notes, and snippets.

@tatac1
Last active December 5, 2022 07:55
Show Gist options
  • Save tatac1/8670611 to your computer and use it in GitHub Desktop.
Save tatac1/8670611 to your computer and use it in GitHub Desktop.
a http-conduit sample
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Conduit
import Network.HTTP.Types.Status
import Network
import Data.Time.Clock
import Data.Time.Calendar
import qualified Control.Exception as E
import qualified Data.ByteString.Lazy as L
past :: UTCTime
past = UTCTime (ModifiedJulianDay 56200) (secondsToDiffTime 0)
future :: UTCTime
future = UTCTime (ModifiedJulianDay 562000) (secondsToDiffTime 0)
cookie :: Cookie
cookie = Cookie { cookie_name = "password_hash"
, cookie_value = "abf472c35f8297fbcabf2911230001234fd2"
, cookie_expiry_time = future
, cookie_domain = "vul.jp"
, cookie_path = "/"
, cookie_creation_time = past
, cookie_last_access_time = past
, cookie_persistent = False
, cookie_host_only = False
, cookie_secure_only = False
, cookie_http_only = False
}
main = withSocketsDo $ do
let url = "http://vul.jp/secret-page"
request' <- parseUrl url
let request = request' { cookieJar = Just $ createCookieJar [cookie] }
eitherResp <- E.try (withManager $ httpLbs request)
case eitherResp of
Left (StatusCodeException s _ _)
| statusCode s == 403 -> putStrLn "login failed."
| statusCode s == 404 -> putStrLn "Dose not exist."
| otherwise -> return ()
Right resp -> print (L.length (responseBody resp))
@tatac1
Copy link
Author

tatac1 commented Jan 28, 2014

a sample of http-conduit code dose not work so that i rewrite it
http://hackage.haskell.org/package/http-conduit-2.0.0.4/docs/Network-HTTP-Conduit.html#t:Response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment