如何在Pycurl中执行HTTPS调用?

时间:2014-11-18 15:39:46

标签: python login https pycurl

我想使用`pycurl'登录发送POST请求的网站在HTTPS页面上。我做了以下事情:

import pycurl, urllib
curl = pycurl.Curl()
curl.setopt(pycurl.COOKIEFILE, "")
post = "_username=something&_password=somethingelse&_submit=Login"
curl.setopt(pycurl.URL, "https://www.example.com/login_check")
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.POSTFIELDS, post)
curl.perform()

但我无法登录。可能是因为我的代码改为http调用。虽然我能够执行登录发送' POST'请求在`POSTMAN'

中使用相同的参数

所以似乎登录是正确的,但我在python中实现相同的错误。 Pl指南。

1 个答案:

答案 0 :(得分:0)

根据pycURL文档,您的帖子数据需要是键值对和网址编码:

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)
相关问题