Skip to content

Commit a55605c

Browse files
committed
新增Python版
1 parent 6680f8a commit a55605c

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

APIJSON-Python/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# APIJSON测试 - Python
2+
3+
### 1.下载后解压APIJSON工程
4+
5+
[打开APIJSON的GitHub主页](https://github.com/TommyLemon/APIJSON) > Clone or download > [Download ZIP](https://github.com/TommyLemon/APIJSON/archive/master.zip) > 解压到一个路径并记住这个路径。
6+
7+
<br />
8+
9+
### 2.运行Python脚本
10+
11+
#### Windows
12+
13+
假设解压路径为 D:\Downloads
14+
15+
打开 CMD命令行窗口
16+
cd D:\Downloads\APIJSON-master\APIJSON-Python
17+
python test.py
18+
19+
#### Linux 或 Mac OS
20+
21+
假设解压路径为 /Users/Tommy/Downloads
22+
23+
打开 Terminal终端窗口,然后分别执行:
24+
cd /Users/Tommy/Downloads/APIJSON-master/APIJSON-Python
25+
python test.py
26+
27+
<br />
28+
29+
### 3.测试接口<h3/>
30+
31+
看 命令行控制台。<br />
32+
如果默认url不可用,修改为一个可用的,比如正在运行APIJSON后端工程的电脑的IPV4地址,然后重新运行。
33+
34+
<br />

APIJSON-Python/test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
import urllib2
3+
import json
4+
5+
print '\n{APIJSON @ Python}'
6+
7+
url = 'http://39.108.143.172:8080/get'
8+
print '\nURL: ' + url
9+
10+
data = {
11+
'[]': {
12+
'User': {
13+
'sex': 1
14+
},
15+
'count': 2
16+
}
17+
}
18+
print '\nRequest:\n' + json.dumps(data, indent=2)
19+
20+
headers = {'Content-Type': 'application/json'}
21+
request = urllib2.Request(url=url, headers=headers, data=json.dumps(data))
22+
response = urllib2.urlopen(request)
23+
print '\nResponse:\n' + json.dumps(json.loads(response.read()), indent=2)

0 commit comments

Comments
 (0)