Python将https数据发送到网站

时间:2015-11-20 17:02:09

标签: python https

我想知道如何使用python中的HTTPS将数据发送到网站。

使用http执行此操作似乎很简单,但我无法找到相同的https请求...

先谢谢了! : - )

1 个答案:

答案 0 :(得分:1)

使用requests非常简单:

import requests
r = requests.get('https://example.com')
print r.status_code

如果您想使用urllib2,这是一段直接取自their examples的代码:

>>> import urllib2
>>> req = urllib2.Request(url='https://localhost/cgi-bin/test.cgi',
...                       data='This data is passed to stdin of the CGI')
>>> f = urllib2.urlopen(req)
>>> print f.read()
Got Data: "This data is passed to stdin of the CGI"