curl-and-python

pycurl and custom POST

From: Sagi S <singduck_at_hotmail.com>
Date: Fri, 30 Jan 2009 12:21:40 +0000

Hi
I try to send custom POST request to server. With curl I do it such way:

curl -i -X POST -H "Content-Type: text/json" -d
'[{"command":"connect","refid":1},{"command":"post", "refid":2,
"channel":"chat", "data":"hello world 3"}]' http://media.mysite.com/qrpc

So the question is - how I send it with pycurl??

I've tried this configuration:

jason = [ 'Content-Type:text/json', 'Expect: ' ]

class Curl:
    def __init__(self, url):
        self.url = url
        self.body = StringIO()
        self.http_code = -1
        # pycurl API calls
        self._curl = pycurl.Curl()
        self._curl.setopt(pycurl.URL, self.url)
        self._curl.setopt(pycurl.POST, 1)
        self._curl.setopt(pycurl.HTTPHEADER, jason)
        self._curl.setopt(pycurl.READFUNCTION, open('/tmp/header', 'rb').read)

and in /tmp/header - POST-string [{"command":"connect","refid":1},{"command":"post", "refid":2,
"channel":"chat", "data":"hello world 3"}]
But it doesn't work as need. Need help with forming POST request..
All other options produce errors, POSTFIELD requires "=" etc.
Any help will be appreciated

--
WBR Sergei Sh
_________________________________________________________________
More than messages–check out the rest of the Windows Live™.
http://www.microsoft.com/windows/windowslive/

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2009-01-30