Skip to content

Instantly share code, notes, and snippets.

@yuuichi-fujioka
Last active December 16, 2015 06:59
Show Gist options
  • Save yuuichi-fujioka/5395327 to your computer and use it in GitHub Desktop.
Save yuuichi-fujioka/5395327 to your computer and use it in GitHub Desktop.
http request
import httplib
def http_req(host, port = 80, method = 'GET', uri = '', headers = {}, body=''):
con = httplib.HTTPConnection(host, port)
con.request(method, uri, body, headers)
resp = con.getresponse()
if resp.status == httplib.OK :
print resp.read()
else:
print 'Error Status=%(status)d Message=%(msg)s'%{'status':resp.status, 'msg':resp.read()}
con.close()
import requests
resp = requests.get('http://www.yahoo.co.jp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment