Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Network.Curl POST body not showing up (Michael Xavier)
----------------------------------------------------------------------
Message: 1
Date: Tue, 10 May 2011 22:25:56 -0700
From: Michael Xavier <[email protected]>
Subject: [Haskell-beginners] Network.Curl POST body not showing up
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
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
curl -H "Content-Type: application/json" -d "{blah:42}" -u 'myuser:mypass'
https://example.com/api.json
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
Host: example.com
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
http://www.michaelxavier.net
--
Michael Xavier
http://www.michaelxavier.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110510/349aedec/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 35, Issue 20
*****************************************