python post请求

 1 from httplib2 import Http
 2 def postDada():
 3     http=Http()
 4     heads={"pragma":"no-cache"}
 5     data=""
 6     count=1
 7     for i in range(count):
 8         res_h,res_b=http.request("http://urltracker.yunfan.com:8081/?opt=2",
 9                                  method="POST",heads=heads,body=data)
10         print i,res_b

python 发送http post请求:
  使用httplib2库中Http类中的request方法,利用循环,可以发送多次请求。

相比get请求http.request()方法中参数多method="POST",body

from httplib2 import Http
def httpGet():
    http=Http()
    count=1
    for i in range(count):      
        res_h,res_b=http.request("http://www.baidu.com")
        print i,res_b

httpGet()

python 发送http get请求

你可能感兴趣的:(python post请求)