当前位置: 首页 > 工具软件 > PycURL > 使用案例 >

pycurl 应用

姜俊民
2023-12-01
import os
import pycurl
import StringIO
import sys 
import urllib




def job(arg):
    c = pycurl.Curl()
    c.setopt(pycurl.CONNECTTIMEOUT, 60)
    c.setopt(pycurl.TIMEOUT, 300)
    c.setopt(pycurl.URL, "http://xxx.json")
#    -d "a=1&b=2"
    post_data = {"a":"1",

                 "b":"2"

                 "arg":arg}

    # Option -d/--data <data>   HTTP POST data
    c.setopt(c.POSTFIELDS,  urllib.urlencode(post_data))


    c.setopt(pycurl.HTTPHEADER, ["Accept:"])
    b = StringIO.StringIO()
    c.setopt(pycurl.WRITEFUNCTION, b.write)
    c.setopt(pycurl.FOLLOWLOCATION, 1)
    c.setopt(pycurl.MAXREDIRS, 5)
    c.perform()
    print b.getvalue()
    
print "python curl  start"
#sys.stdout = open("log.txt", "write")
handler = open("data.txt")
line = handler.readline()


while line :
    arg=int(line)
   
    line = handler.readline()
    job(arg)
    
handler.close()
sys.exit()





 类似资料: