Debian Codegraph @

examples/quickstart/form_post.py

raw
1 #! /usr/bin/env python
2 # vi:ts=4:et
3
4 import pycurl
5 from urllib.parse import urlencode
6
7 c = pycurl.Curl()
8 c.setopt(c.URL, 'https://httpbin.org/post')
9
10 post_data = {'field': 'value'}
11 # Form data must be provided already urlencoded.
12 postfields = urlencode(post_data)
13 # Sets request method to POST,
14 # Content-Type header to application/x-www-form-urlencoded
15 # and data to send in request body.
16 c.setopt(c.POSTFIELDS, postfields)
17
18 c.perform()
19 c.close()