2

私は単純なHTTPを使用してHTTPクラスの応答タイプだと思いますから応答コード(200,404など)を取得しようとしていますこれまで:

--how to get the http response Int from response
getStatusCode response  = print 0

--this works...
--- othercode ---
rsp <- simpleHTTP (defaultGETRequest_ clean_uri) 
file_buffer <- getResponseBody(rsp)
--this fails
response = (getStatusCode rsp)
4

1 に答える 1

3

あなたが望むのは

getResponseCode :: Result (Response ty) -> IO ResponseCode

Network.HTTPHTTP-4000.2.4 以降を使用している場合は、モジュールから。の以前のバージョンでは、以下に示すフィールドの方法と同様に、フィールドHTTPで自分自身をパターン マッチングする必要があるようです。rspCoderspReason

理由に興味がある場合は、のrspReasonフィールドをResponse使用してください。

rsp <- simpleHTTP ...

あなたが持っている

rsp :: Either ConnError (Response ty)  -- Result is a type synonym for (Either ConnError)

ごとに理由にアクセスできます

let reason = case rsp of
               Left err -> show err  -- for example
               Right response -> rspReason response
putStrLn $ "Here's why: " ++ reason
于 2012-10-16T19:12:31.487 に答える