首页 > 代码库 > python2 httplib 笔记

python2 httplib 笔记

python2  httplib 笔记

#coding=utf-8  ‘‘‘Created on 2014年9月25日@author: cocoajin‘‘‘import httplib,urllibbase=httpbin.org #不需要添加 "http://"con=httplib.HTTPConnection(base)ip = /ipcon.request(GET,ip)re=con.getresponse()print re.getheaders()print re.read()con.close()#GET con=httplib.HTTPConnection(base)parm={name:nick,age:18}gets=/getcon.request(GET, gets+?+urllib.urlencode(parm))re=con.getresponse()print re.getheaders()print re.read()con.close()#POST con=httplib.HTTPConnection(base)parm={name:nick,age:18}posts=/post#headers = {"Content-type":"application/json","Accept":"text/plain"} jsonheaders = {"Content-type":"application/json","Accept":"text/plain"} #formcon.request(POST, posts,urllib.urlencode(parm),headers)re=con.getresponse()print re.getheaders()print re.read()con.close()#文件上传使用 "multipart/form-data"

 

python2 httplib 笔记