2016-05-07 7 views
1

HaskellにWebページが存在するかどうかを確認する方法を探しています。サーバーはHTTP2/HTTPSのみであり、サーバーントアプリケーションにページが存在するかどうかを確認しようとしています。HaskellでWebページのステータスコードを取得

ステータスコードが200か404かどうかを確認するためのドキュメントがあるHaskellパッケージはありますか?そして、強力なHTTPSとHTTP2サーバーで作業していますか?私は現在のhttp-導管と持っていますが、私は奇妙な例外を受けてるものをここで

(TlsExceptionHostPort(HandshakeFailed(Error_Protocolが( "ハローサーバーを期待して、警告を得た:[(AlertLevel_Fatal、HandshakeFailure)]"、真、HandshakeFailure))) "thibaud.dauce.fr" 443およびStatusCodeException)。

... other imports 
import qualified Network.HTTP.Conduit as HTTP 

... other types 
type AppM = ReaderT Config (EitherT ServantErr IO) 

newComment :: String -> OneComment -> AppM Int64 
newComment baseUrl oneComment = do 
    time <- liftIO getCurrentTime 
    response <- HTTP.withManager $ \manager -> do 
     request <- HTTP.parseUrl $ url oneComment 
     HTTP.httpLbs request manager 
    case (statusIsSuccessful $ HTTP.responseStatus response, startswith baseUrl (url oneComment)) of 
     (_, False) -> return 0 
     (True, True) -> do 
      theNewComment <- runDb $ insert $ Comment (url oneComment) (content oneComment) time 
      return $ fromSqlKey theNewComment 
     _ -> return 0 
+1

を使用していくつかの例は[ 'wreq'パッケージ](http://www.serpentine.com/wreq/)を見てください – ErikR

答えて

3

wreq

{-# LANGUAGE OverloadedStrings #-} 

import Network.Wreq 
import Control.Lens 
import Control.Exception as E 
import Network.HTTP.Client (HttpException) 

test1 = do 
    r <- get "https://httpbin.org/get" 
    print $ r ^. responseStatus . statusCode 

-- throws an exception 
test2 = do 
    r <- get "https://www.google123123.com" 
    print $ r ^. responseStatus . statusCode 

testUrl url = do 
    r <- get url 
    return $ r ^. responseStatus . statusCode 

-- catching the exception 
test3 = do 
    st <- testUrl "https://www.google123123123.com" `E.catch` handler 
    print st 
    where 
    handler :: HttpException -> IO Int 
    handler _ = return 999 
+0

私はあなたのコードを使用して、私が得ます) "thibaud.dauce.fr" 443 '私のウェブサイトが完全に有効なHTTPS証明書であっても(つまり、本当に有効なHTTPS証明書として)、TlsExceptionHostPort(HandshakeFailed(Error_Protocol(" ... –

+0

'wreq'は[' hs-tls'](https://github.com/vincenthz/hs-tls)を使用しており、特定の種類の証明書と暗号に問題があります。私はgithubリポジトリから最新バージョンをビルドし、 'tis-simpleclient'プログラムを実行してより多くの診断情報を取得します。また、特定のISPプロバイダに問題があります。 – ErikR

+0

数日前にhttps://github.com/vincenthz/hs-tls/issues/142の詳細情報を公開してください。 'tls-simpleclient'も失敗するようです...あなたの助けとあなたのコードサンプルをもう一度お寄せいただきありがとうございます! –

関連する問題