Python---httplib2

import urllib.request as ur
import http.client as hc
import httplib2
import urllib.parse as up

def httplibtwo1():
    print('===================httplib2========================')
    url='http://www.12306.cn/mormhweb/'
    httplib2.debuglevel=1
    h = httplib2.Http('.cache')
    h.add_credentials('xfei.zhang','11111111')
    print('=================request=========================')
    response, content=h.request(url,'GET',headers={'cache-control':'no-cache'})
    print('\n=================response=======================')
    print(response.items())
    print(response.status)
    print(response.fromcache)
    data={'age':'30','name':'jasca'}
    data2=up.urlencode(data)
    print(data2)

if __name__ == '__main__':
    httplibtwo1()

 

posted @ 2015-12-28 20:18  xfei.zhang  阅读(419)  评论(0编辑  收藏  举报