LoginSignup
1
1

More than 5 years have passed since last update.

Network.HTTP

Posted at

ネスト深くなるのをなんとかする術は早めに見つけておきたい。

% runhaskell
import Network.HTTP

main :: IO ()
main = do
    let req = getRequest "http://d.hatena.ne.jp/hiratara/"
    result <- simpleHTTP req
    case result of
      Left x  -> error $ show x
      Right y ->
          do
            if (rspCode y) /= (2, 0, 0)
            then error $ "bad status code" ++ (show $ rspCode y)
            else return ()
            putStrLn $ take 256 $ rspBody y

【実行結果】
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:og="http://ogp.me/ns#">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Cont
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1