import urllib
import urllib2
import requests
print "demo1"
URL="https://api.github.com"
def ull():
response=urllib2.urlopen(URL)
print "Response >>>>"
print response.info()#?????????
def user_paramter():
#??????
parmes=urllib.urlencode({"wd":"pyhon"})
print "Parmters >>"
request=urllib2.Request("?".join([URL,parmes]))
request.add_header("User-Agent","Mozilla/5.0")
#????????
response=urllib2.urlopen(request)
#????
print "Response >>>>"
#?????????
def build_url(url):
return "/".join([URL,url])
def user_request():
# parmertes={"wd":"python"}
response=requests.get(build_url("user/emails"),auth=("imoocdemo","imoocdemo123"))
print "Headers>>"
print response.text
print "Response Body"
def params_request():
response=requests.get(build_url("users"),params={"since":11})
print response.text
print response.url
print response.request.headers
def patch_request():
#response=requests.patch(build_url("user"),auth=("imoocdemo","imoocdemo123"),json={"name":"babymooc3","email":"hello-world@imooc.org"})
response=requests.post(build_url("user"),auth=("imoocdemo","imoocdemo123"),json=["Good@163.com"])
print response.headers
print response.request.body
print response.status_code
patch_request()