Created
December 11, 2013 06:13
-
-
Save Hyunho/7905793 to your computer and use it in GitHub Desktop.
clone
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
""" | |
This is clone of requests python package | |
if server is inconvenience to install python package, I want to use this | |
""" | |
import urllib2 | |
import urllib | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
def post(url, data): | |
if type(data) == str: | |
req = urllib2.Request(url=url, data=data) | |
if type(data) == dict: | |
req = urllib2.Request(url=url, data=urllib.urlencode(data)) | |
f = urllib2.urlopen(req) | |
return Response(f.read()) | |
class Response: | |
def __init__(self, content): | |
self.content = content | |
def json(self): | |
return json.loads(self.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment