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

时间:2018-01-19 02:12:40

标签: python http 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请求是什么样的。 有没有办法做到这一点?

1 个答案:

答案 0 :(得分:2)

您可以使用VERBOSE选项,像curl -v一样工作,将请求/响应标题打印到stderr

c.setopt(pycurl.VERBOSE, 1)

详情请见pycurl doc