2

I have a simple api endpoint:

http://example.de/create.json

I need to send the following via POST:

-text

-url

-username

The curl command for this task looks like this:

curl --data-urlencode "text=Beispieltext" -d "url=http://google.de" -d "username=User1" http://example.de/create.json

I want to implement this in my code. I want to submit data to the api and work with the answer from the api. Actually I have no idea where to start. I read and tried a lot about Pycurl, urllib2 and subprocess but now I don't understand anything anymore :D

How would you do that? I need help, I don't know where to start!

4

2 に答える 2

1

ものすごく単純。次のようになります。

import pycurl
import StringIO

c = pycurl.Curl()
c.setopt(c.URL, 'http://example.de/create.json')
output = StringIO.StringIO()
c.setopt(c.WRITEFUNCTION, output.write)
c.setopt(c.POSTFIELDS, 'your post data')
c.perform()

結果は output.getvalue() にあります。完了したら output.close() を忘れないでください。

于 2013-01-31T12:00:45.140 に答える
0

libcurlの(右の列の例を参照)

于 2013-10-30T22:19:09.143 に答える