Hi all,
I was hoping one of you was pretty proficient with
Network.Curl to help me out, as I am not. I need to post JSON to
an HTTPS endpoint using HTTP Basic Authentication. The endpoint
will not accept the request unless the content-type is set to
application/json.
If I were using the curl utility, I'd do something like
I'd really like to use curl's curlGetString because the
return type is perfect, the code and the body.
I've tried curlGetString, curlPost and curlMultiPost and all
combinations of CurlOption, but I can either get it to send the
correct content type header with empty content or send the post
body with the content type defaulted to urlencoded or
multipart/form-data. My code right now looks something like:
doPost :: (ToJSON a) => T.Text -> T.Text -> T.Text
-> a -> CampfireM (CurlCode, String)
doPost key sub path pay = liftIO $ curlGetString (url path
sub) opts
where opts = method_POST ++ curlOpts
key ++ [CurlVerbose True, post, ct]
post = CurlPostFields [T.unpack
encPay]
ct = CurlHttpHeaders
["Content-Type: application/json"]
encPath = encodePath path encPay
encPay = encodePayload pay
The post fields will not be in the form of "key=value", but
rather a JSCODE:
* Server auth using Basic with user 'SECRET_KEY'
> POST /rooms/287132/speak.json HTTP/1.1
Authorization: Basic SECRET_KEY
Accept: */*
Content-Type: application/json
Content-Length: 103
* The requested URL returned error: 500
* Closing connection #0
* HTTP response code said error
It would seem to me from this output that no actual content
was sent. What am I doing wrong? I'd really like to use
curlGetString instead of some of the more complex curl
functions.
Thanks!
--
Michael Xavier
--
Michael Xavier
http://www.michaelxavier.net
_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners