File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 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 />
Original file line number Diff line number Diff line change 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 '\n URL: ' + url
9+
10+ data = {
11+ '[]' : {
12+ 'User' : {
13+ 'sex' : 1
14+ },
15+ 'count' : 2
16+ }
17+ }
18+ print '\n Request:\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 '\n Response:\n ' + json .dumps (json .loads (response .read ()), indent = 2 )
You can’t perform that action at this time.
0 commit comments