Unable to HTTP PUT with libcurl to django-piston

Posted by Jesse Beder on Stack Overflow See other posts from Stack Overflow or by Jesse Beder
Published on 2010-05-13T08:38:30Z Indexed on 2010/05/13 17:24 UTC
Read the original article Hit count: 290

Filed under:
|
|
|
|

I'm trying to PUT data using libcurl to mimic the command

curl -u test:test -X PUT --data-binary @data.yaml "http://127.0.0.1:8000/foo/"

which works correctly. My options look like:

curl_easy_setopt(handle, CURLOPT_USERPWD, "test:test");
curl_easy_setopt(handle, CURLOPT_URL, "http://127.0.0.1:8000/foo/");
curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_data);
curl_easy_setopt(handle, CURLOPT_READDATA, &yaml);
curl_easy_setopt(handle, CURLOPT_INFILESIZE, yaml.size());
curl_easy_perform(handle);

I believe the read_data function works correctly, but if you ask, I'll post that code.

I'm using Django with django-piston, and my update function is never called! (It is called when I use the command line version above.)

libcurl's output is:

* About to connect() to 127.0.0.1 port 8000 (#0)
*   Trying 127.0.0.1... * connected
* Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
* Server auth using Basic with user 'test'
> PUT /foo/ HTTP/1.1
Authorization: Basic dGVzdDp0ZXN0
Host: 127.0.0.1:8000
Accept: */*
Content-Length: 244
Expect: 100-continue

* Done waiting for 100-continue
** this is where my read_data handler confirms: read 244 bytes **
* HTTP 1.0, assume close after body
< HTTP/1.0 400 BAD REQUEST
< Date: Thu, 13 May 2010 08:22:52 GMT
< Server: WSGIServer/0.1 Python/2.5.1
< Vary: Authorization
< Content-Type: text/plain
< 
Bad Request* Closing connection #0

© Stack Overflow or respective owner

Related posts about curl

Related posts about django