【问题标题】:HTTPS GET request & read JSON replyHTTPS GET 请求并读取 JSON 回复
【发布时间】:2012-02-26 22:26:37
【问题描述】:

正如标题所说,我需要发送一个 HTTPS GET 请求,然后以纯文本格式读取 JSON 回复。我更喜欢 python,但我也可以使用 perl。

编辑:好的,现在我可以从页面获取数据,但是回复数据是 SSL 加密的,我将如何解密它?

【问题讨论】:

  • urllib2json 应该可以完成这项工作

标签: python json perl https


【解决方案1】:

Python:

import json
import urllib2
data = json.loads(urllib2.urlopen(url).read())

【讨论】:

  • +1,但值得注意的是,urllib2 要处理 HTTPS 请求,Python 安装需要支持 SSL。
【解决方案2】:

对于 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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 2015-11-22
    • 2018-03-25
    • 1970-01-01
    • 2011-06-13
    • 2012-07-07
    相关资源
    最近更新 更多