Created
September 24, 2013 01:06
-
-
Save mmitou/6679095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE OverloadedStrings #-} | |
| import Network.HTTP.Conduit | |
| import Data.Conduit | |
| import Data.Conduit.Binary | |
| import Control.Monad.IO.Class (liftIO) | |
| import Data.Conduit | |
| import System.IO | |
| logonUrl="http://localhost" | |
| userAccount = [ ("user", "foo") | |
| , ("pass", "bar")] | |
| test :: IO () | |
| test = runResourceT $ do | |
| -- urlをパースしてリクエストオブジェクトを作る | |
| case parseUrl logonUrl of | |
| Nothing -> return () | |
| -- managerオブジェクトがコネクションを管理する | |
| Just req -> withManager $ \manager -> do | |
| -- リクエストボディにurlエンコーディング形式で値を追加する | |
| -- この戻り値は、POSTでContent-Typeがx-www-form-urlencodedになる | |
| let loginRequest = urlEncodedBody userAccount req | |
| -- httpでリクエストを投げて、レスポンスを取得する | |
| response <- http loginRequest manager | |
| liftIO $ do | |
| print $ responseStatus response | |
| mapM_ print $ responseHeaders response | |
| responseBody response $$+- sinkHandle stdout | |
| return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment