获取Haskell中网页的状态代码
我正在设法检查Haskell中是否存在网页。服务器仅为HTTP2/HTTPS,我正在尝试检查该页面是否存在于服务应用程序中 是否有任何Haskell软件包具有良好的文档,只需检查状态代码是200还是404?以及使用强大的HTTPS和HTTP2服务器 这里是我目前使用http导管的情况,但我收到了奇怪的异常(TlsExceptionHostPort(HandshakeFailed(Error_Protocol(“期望服务器hello,得到警报:[(AlertLevel_Fatal,HandshakeFailure)]),True,HandshakeFailure))“thibaud.dauce.fr”443和StatusCodeException)获取Haskell中网页的状态代码,haskell,http-conduit,servant,Haskell,Http Conduit,Servant,我正在设法检查Haskell中是否存在网页。服务器仅为HTTP2/HTTPS,我正在尝试检查该页面是否存在于服务应用程序中 是否有任何Haskell软件包具有良好的文档,只需检查状态代码是200还是404?以及使用强大的HTTPS和HTTP2服务器 这里是我目前使用http导管的情况,但我收到了奇怪的异常(TlsExceptionHostPort(HandshakeFailed(Error_Protocol(“期望服务器hello,得到警报:[(AlertLevel_Fatal,Handshak
。。。其他进口
将合格的Network.HTTP.conductor导入为HTTP
... 其他类型
类型AppM=ReaderT Config(EitherT ServantErr IO)
newComment::String->OneComment->AppM Int64
newComment baseUrl oneComment=do
时间
然后,新命令返回0
一些使用
{-#语言重载字符串}
导入网络.Wreq
进口管制.镜头
导入控制。异常为E
导入Network.HTTP.Client(HttpException)
test1=do
r看一看“我使用你的代码”,我得到一个TlsExceptionHostPort(HandshakeFailed(错误协议(“期望服务器你好,得到警报:[(警报级别致命,握手失败)]”),True,HandshakeFailure))“thibaud.dauce.fr”443
即使我的网站作为一个完全有效的HTTPS证书…wreq
使用,某些类型的证书和密码也存在问题。我将从github repo构建最新版本,并运行tis simpleclient
程序以获取更多诊断信息。此外,还可以查看问题跟踪程序-特定ISP提供商存在问题。几天前已经发布了一个问题以获得更多信息<代码>tls simpleclient
似乎也失败了…再次感谢您的帮助和代码示例!
... 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
{-# 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