【发布时间】:2012-02-26 22:26:37
【问题描述】:
正如标题所说,我需要发送一个 HTTPS GET 请求,然后以纯文本格式读取 JSON 回复。我更喜欢 python,但我也可以使用 perl。
编辑:好的,现在我可以从页面获取数据,但是回复数据是 SSL 加密的,我将如何解密它?
【问题讨论】:
-
urllib2和json应该可以完成这项工作
正如标题所说,我需要发送一个 HTTPS GET 请求,然后以纯文本格式读取 JSON 回复。我更喜欢 python,但我也可以使用 perl。
编辑:好的,现在我可以从页面获取数据,但是回复数据是 SSL 加密的,我将如何解密它?
【问题讨论】:
urllib2 和 json 应该可以完成这项工作
Python:
import json
import urllib2
data = json.loads(urllib2.urlopen(url).read())
【讨论】:
urllib2 要处理 HTTPS 请求,Python 安装需要支持 SSL。
对于 Perl:
use JSON; # We will use this to decode the result
use LWP::Simple; # We will use this to get the encoded data over HTTPS
use Data::Dumper; # We will use this to display the result
# Download the json data
my $encoded_json = get("https://domain.com/url");
# Decode the json data
my $result = decode_json($encoded_json);
# Show the result in readable form
print Dumper($result);
【讨论】: