#get接口调用 import urllib import urllib2 get_url = "http://10.10.3.63/test?id=123&name=nba" cookie_headers = { "Cookie" : "person_id=2468" } req = urllib2.Request(url=get_url,headers=cookie_headers) res_data = urllib2.urlopen(req) res = res_data.read() print res
#post接口调用 import urllib import urllib2 args_data = { 'id':'321', 'name':'cba' } args_data_urlencode = urllib.urlencode(args_data) post_url = "http://10.10.3.63/test" cookie_headers = { "Cookie" : "person_id=24681111;bureau_id=0000" } req = urllib2.Request(url = post_url, data = args_data_urlencode, headers=cookie_headers) res_data = urllib2.urlopen(req) res = res_data.read() print res