curl-and-python
Re: problem using pycurl for simple POST request
Date: Wed, 25 May 2005 13:51:24 -0400
Looks like part of my answer is to use the :
curl.(c.POST, 1) and combined read function to get my string posted.
Andrew Bushnell wrote:
> Hi,
>
> I am moving some code over to use pycurl (great library btw, thanks!!)
> but I am having difficulty replacing a section of code using pycurl. The
> old code/algorithm looks as something along the lines of:
>
> connection = HTTPConnection(host)
> connection.putheader("POST", "URLTOPOSTTO")
> connection.putheader("content-type", "text/xml")
> connection.putheader("Content-length", str(len(mydata)))
> connectino.putheader("mycustomheader", "mycustomvalue")
> connection.endheaders()
> connection.send(data)
>
> ...
>
> then I get the reply and in this case, it is "data" to download/read off
> of the socket.
>
> I need/want to use pycurl to get round some proxy/ssl issues which it
> handles beautifully for me in other areas. However, I am stuck on 2
> questions/issues:
>
> #1: it seems to set the HTTPPOST, my data needs to be in the form of a
> list with field, data... This is not the case for me.
>
> #2: will a registered WRITEFUNCTION get the data requested via my post
> and custom header? Basically, the post contains an "action" to be
> peformed by the remote. When finished, it writes back the data,
> including content-type and length and based on that I read the data.
>
> Some curl psuedocode that I was working with:
>
> class Test:
> def myfunction():
> ...
> c = pycurl.Curl()
> t = Test()
> c.setopt(c.URL, 'url_posting_to')
> # insecure for now..
> c.setopt(c.SSL_VERIFYPEER, False)
> c.setopt(c.SSL_VERIFYHOST, 1)
> c.setopt(c.PROXY, 'proxy')
> # tunnel to get to secure site.
> c.setopt(c.HTTPPROXYTUNNEL, True)
> c.setopt(c.VERBOSE, 1)
> # mydata is a python string object...
> c.setopt(c.HTTPPOST, mydata)
> c.setopt(c.WRITEFUNCTION, t.myfunction)
> c.perform()
> c.close()
>
>
> I will keep fishing/digging, but any help is appreciated.
>
-- ************************************ Andrew Bushnell Lead Development Engineer Fluent Inc. 10 Cavendish Court Centerra Resource Park Lebanon, NH 03766 awb_at_fluent.com Phone: 603-643-2600, ext. 757 Fax: 603-643-1721 www.fluent.com ************************************ _______________________________________________ http://cool.haxx.se/mailman/listinfo/curl-and-pythonReceived on 2005-05-25