
I would be interested in this as well. I'm trying to use Network.Curl for a personal project, also using a method_post, and am not able to get a response. Though I know it's connecting. I _think_ that I need to use CurlWriteFunction, but I'm still new to Haskell & not sure how to work with that option. Bryce On 05/10/2011 10:25 PM, Michael Xavier wrote:
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 http://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
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners