Python调用HTTP接口并传递cookie

#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

 

上一篇:C# 从Json中获取byte[] 二进制数据


下一篇:教学思路SQL之入门习题《学生成绩》 四、多表连接关系查询