pycurl:如何验证发出POST请求

时间:2017-06-10 10:00:10

标签: python-2.7 curl post urlencode pycurl

通过cURL(Windows)使用以下命令:curl -u username:password "https://website.com/update/" --data "simChangesList=%5B%7B%22simId%22%3A760590802%2C%22changeType%22%3A2%2C%22targetValue%22%3A%22000307%22%2C%22effectiveDate%22%3Anull%7D%5D" --compressed 我能够根据-u开关成功发布经过身份验证的数据。

如何使用pycurl成功创建相同的POST请求?

import urllib
import pycurl

enc = urllib.quote('simChangesList:[{"simId":760590802,"changeType":2,"targetValue":000307,"effectiveDate":null}]')
c = pycurl.Curl()
c.setopt(c.URL, 'https://website.com/update/')

c.setopt(c.POSTFIELDS, enc)
c.setopt(c.VERBOSE, True)

c.perform()
c.close()

执行上面的代码不会POST我希望它做的数据,我怀疑这是因为我要求身份验证,根据Windows cURL版本。

如何成功修改我的代码,以便我可以对我的数据进行POST身份验证?

0 个答案:

没有答案
相关问题