有没有办法在pycurl中获取完整的http请求?

Is there a way to get the full http request in pycurl?

c = pycurl.Curl()
c.setopt(c.URL, 'https://httpbin.org/post')

post_data = {'field': 'value'}
# Form data must be provided already urlencoded.
postfields = urlencode(post_data)
# Sets request method to POST,
# Content-Type header to application/x-www-form-urlencoded
# and data to send in request body.
c.setopt(c.POSTFIELDS, postfields)

c.perform()
c.close()

这是官方文档中的示例。 我想知道 http 请求是什么样的。 有办法吗?

你可以使用 VERBOSE 选项,像 curl -v 一样工作,将打印 request/response headers 到 stderr:

c.setopt(pycurl.VERBOSE, 1)

查看 pycurl doc 的更多详细信息。