-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
import requests | ||
|
||
URL_IP = 'http://localhost:8000/ip' | ||
URL_GET = 'http://localhost:8000/get' | ||
|
||
|
||
def use_simple_requests(): | ||
response = requests.get(URL_IP) | ||
print '>>>>Response Headers:' | ||
print response.headers | ||
print '>>>>Response body:' | ||
print response.text | ||
|
||
|
||
def use_params_requests(): | ||
params = {'param1': 'hello', 'param2': 'world'} | ||
response = requests.get(URL_GET, params=params) | ||
print '>>>>Response Headers:' | ||
print response.headers | ||
print '>>>>Status Code:' | ||
print response.status_code | ||
print '>>>>Reason:' | ||
print response.reason | ||
print '>>>>Request body:' | ||
print response.text | ||
|
||
if __name__ == '__main__': | ||
print '>>>Use simple requests:' | ||
use_simple_requests() | ||
print '' | ||
print '>>>Use params requests:' | ||
use_params_requests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
import urllib | ||
import urllib2 | ||
|
||
URL_IP = 'http://localhost:8000/ip' | ||
URL_GET = 'http://localhost:8000/get' | ||
|
||
|
||
def use_simple_urllib2(): | ||
response = urllib2.urlopen(URL_IP) | ||
print '>>>>Response Headers:' | ||
print response.info() | ||
print '>>>>Response body:' | ||
print ''.join([line for line in response.readlines()]) | ||
|
||
|
||
def use_params_urllib2(): | ||
params = urllib.urlencode({'param1': 'hello', 'param2': 'world'}) | ||
response = urllib2.urlopen('?'.join([URL_GET, '%s']) % params) | ||
print '>>>>Response Headers:' | ||
print response.info() | ||
print '>>>>Status Code:' | ||
print response.getcode() | ||
print '>>>>Request body:' | ||
print ''.join([line for line in response.readlines()]) | ||
|
||
if __name__ == '__main__': | ||
print '>>>Use simple urllib2:' | ||
use_simple_urllib2() | ||
print '' | ||
print '>>>Use params urllib2:' | ||
use_params_urllib2() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
click==6.6 | ||
decorator==4.0.10 | ||
Flask==0.11.1 | ||
gunicorn==19.6.0 | ||
httpbin==0.4.1 | ||
itsdangerous==0.24 | ||
Jinja2==2.8 | ||
MarkupSafe==0.23 | ||
requests==2.10.0 | ||
six==1.10.0 | ||
Werkzeug==0.11.10 |