[Haskell-beginners] Network.HTTP.Conduit - body in REST/POST request
Miro Karpis
miroslav.karpis at gmail.com
Wed May 28 13:21:18 UTC 2014
so this did the trick:
test :: IO ()
test = do
r <- parseUrl $ "http://localhost:3000/readbody"
let r_ = urlEncodedBody [("?nonce:", "2"), ("&method", "getInfo")] r
let request = r_
{ requestBody = (RequestBodyBS s)}
response <- withManager $ httpLbs request
putStrLn $ show request
print $ responseBody response
On Wed, May 28, 2014 at 2:48 PM, Miro Karpis <miroslav.karpis at gmail.com>wrote:
> Hi, I'm having difficulties with sending body parameters/values in a POST
> request. It seems that the server does not receive in body.
>
> ideas/comments very welcome ;-)
>
> cheers,
> m.
>
>
> {-# LANGUAGE OverloadedStrings #-}
>
> import Network.HTTP.Conduit
> import Data.Word(Word8)
> import Data.ByteString.Lazy(pack)
> import qualified Data.ByteString.Char8 as B
>
> x :: B.ByteString
> x = "?value=10"
>
> post = do
> r <- parseUrl "http://postcatcher.in/catchers/5385d4e0b6887c0200000071"
> putStrLn $show r
> let request = r
> { secure = True
> , method = "POST"
> , requestBody = RequestBodyBS s
> , requestHeaders = (requestHeaders r) ++ [("Content-Type",
> "application/json")]}
> putStrLn $ show request
> response <- withManager $ httpLbs request
> print $ responseBody response
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20140528/ea1d3974/attachment.html>
More information about the Beginners
mailing list