Created
August 19, 2014 08:24
-
-
Save dpwiz/f2c148683037f031495a to your computer and use it in GitHub Desktop.
Unviersal wrapper for POX protocols.
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
module PlainOldXML where | |
import Network.HTTP.Conduit | |
import Text.XML | |
import Text.XML.Cursor | |
xmlQuery :: Manager -> String -> Document -> IO Cursor | |
xmlQuery manager url doc = do | |
putStrLn "Request:" >> BSL.putStrLn (renderLBS (def { rsPretty = True }) doc) | |
req <- parseUrl url | |
let request = req { method = "POST" | |
, responseTimeout = Just 15000000 | |
, requestHeaders = [ ("Content-Type", "text/xml; charset=utf-8") ] | |
, requestBody = RequestBodyLBS $ renderLBS def doc | |
, checkStatus = \_ _ _ -> Nothing | |
} | |
resp <- httpLbs request manager | |
BSL.putStrLn (responseBody resp) | |
let reply = parseLBS_ def | |
-- . convertFuzzy Transliterate "windows-1251" "utf-8" | |
. responseBody | |
$ resp | |
putStrLn "Reply:" >> BSL.putStrLn (renderLBS (def { rsPretty = True }) reply) | |
return $ fromDocument reply |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment