Last active
November 11, 2017 04:03
-
-
Save naoto-ogawa/cb16dda04b3f1f2a141eb75550901a49 to your computer and use it in GitHub Desktop.
Haskell TLS Connection Sample
This file contains 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 #-} | |
module Main where | |
import Prelude hiding (getContents) | |
import qualified Data.ByteString as B | |
import qualified Data.ByteString.Char8 as C | |
import Data.Default.Class | |
import Network.Connection | |
import Network.TLS | |
main = do | |
ctx <- initConnectionContext | |
con <- connectTo ctx ConnectionParams | |
{ connectionHostname = "somewehre" | |
, connectionPort = 443 | |
, connectionUseSecure = Nothing | |
, connectionUseSocks = Nothing | |
} | |
connectionSetSecure ctx con def | |
connectionPut con "Password=QWERT\n" -- invalid date | |
contents <- getContents con B.empty | |
mapM_ print (C.split '\n' contents) | |
connectionClose con | |
getContents :: Connection -> B.ByteString -> IO B.ByteString | |
getContents con acc = do | |
lines <- connectionGetChunk con | |
-- putStrLn $ show lines | |
-- putStrLn $ show $ B.null lines | |
if B.null lines | |
then return acc | |
else getContents con $ acc `B.append` lines | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example of accessing to google.