Haskell 在curlGetResponse中处理无连接情况_

Haskell 在curlGetResponse中处理无连接情况_,haskell,curl,Haskell,Curl,当使用curlGetResponse\uuu时,是否有方法或特殊的curl选项来识别无连接情况 例如,有一些curl-命令: withCurlDo $ respBody <$> (curlGetResponse_ "google.com" [CurlFailOnError True] ∷ IO (CurlResponse_ [(String, String)] ByteString)) 使用curldo$respBody(curlGetResponse_u“google.com”[

当使用
curlGetResponse\uuu
时,是否有方法或特殊的
curl
选项来识别无连接情况

例如,有一些
curl
-命令:

withCurlDo $ respBody <$> (curlGetResponse_ "google.com" [CurlFailOnError True] ∷ IO (CurlResponse_ [(String, String)] ByteString))
使用curldo$respBody(curlGetResponse_u“google.com”[CurlFailOnError True]∷ IO(CurlResponse(字符串,字符串)]ByteString)
如果有到主机的连接,它将通过testring返回一些
IO

但若并没有任何连接,则需要40秒并返回空字符串


当连接断开且无法访问主机时,是否有方法抛出和异常或某些
值?

您可以使用选项设置适当的超时,然后检查超时错误:

μ> withCurlDo $ respCurlCode <$> (curlGetResponse_ "google.com" [CurlConnectTimeout 1] ∷ IO (CurlResponse_ [(String, String)] String))
CurlOK
μ> withCurlDo $ respCurlCode <$> (curlGetResponse_ "2.2.2.2" [CurlConnectTimeout 1] ∷ IO (CurlResponse_ [(String, String)] String))
CurlOperationTimeout
μ>withCurlDo$respcollcode(curlGetResponse_u“google.com”[CurlConnectTimeout 1]∷ IO(字符串(字符串,字符串)]字符串)
科洛克
μ> 使用curldo$respcollcode(curlGetResponse_u“2.2.2.2”[CurlConnectTimeout 1]∷ IO(字符串(字符串,字符串)]字符串)
卷曲操作超时

因此,对于无连接情况,有一个
CurlCouldntResolveHost
值。谢谢