cURL / Mailing Lists / curl-library / Single Mail

curl-library

Can't use POST forms with an HTTP PUT

From: Paul Bergen <bergen.p0_at_gmail.com>
Date: Tue, 20 Nov 2012 16:08:41 -0800

I have written a client that sends data to a server running an http
RESTful API. One of the requests (URI's) requires me to submit
multiple pieces of data, which I do using curl_formadd
(CURLFORM_COPYNAME/CURLFORM_COPYCONTENTS) to send the data, which is
like a form (ie FirstName, File1, File2, Date, etc.). I then use
CURLOPT_HTTPPOST to send it as a POST. This works.

The developer doing the server side said that to be compliant with a
RESTful API, when we want to update data stored on an existing URI, we
should use a PUT instead of a POST. The data being submitted should
still be exactly the same (ie still a form), only change the verb POST
to PUT. So, instead of CURLOPT_HTTPPOST I use CURLOPT_UPLOAD, and
that changes the verb to PUT, but it doesn't send any of the form
data. The docs for CURLOPT_UPLOAD only describe how to use PUT to
upload a single block of data (like a file upload not a form), but
does not describe how to send multiple blocks of data in a form. From
what I've read on http RESTful API's, it seems it's an approved use of
PUT to send form data, like you do with a POST.

Does anybody know how to do this or where to find a sample? Or is
there some way to just override the verb?
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-11-21