python - Conduit.simpleHttp - perform a request supplied with headers and data -
i have simple application sends http(s) request , print info returned:
import network.http.conduit (simplehttp) simplehttp "http://example.com" >>= b.putstr
how supply request headers? or more concrete, how create request below (written in python) in haskell?
requests.post('https://some-url.com',data=json.dumps({"aaa":"bbbcccddd"}), headers={"content-type":"application/json"})
the documentation doesn't http://hackage.haskell.org/package/http-conduit-1.2.1/docs/network-http-conduit.html
note docs request
:
the constructor info type not exposed. instead, should utilize either def method retrieve default instance, or parseurl
build url, , use records below create modifications.
so can configure request using number of record names. in case need requestheaders
, requestbody
. here example:
{-# language overloadedstrings #-} import data.text (text) import qualified data.aeson aeson import qualified data.map map import network.http.conduit main :: io () main = request <- parseurl "http://example.com" res <- withmanager $ httplbs $ configurerequest request print res configurerequest r = r { method = methodpost, requestheaders = ("content-type", "application/json") : requestheaders r, requestbody = requestbodylbs (aeson.encode $ map.fromlist [("aaa" :: text, "bbbccsddd" :: text)]) }
python haskell networking
No comments:
Post a Comment