pycurl 上传文件 提交
来源:互联网 发布:手机淘宝在哪买彩票 编辑:程序博客网 时间:2024/06/05 02:59
import pycurl
fields = [('field1', 'this is a test using httppost & stuff'),
('field2', (pycurl.FORM_FILE, 'file1.txt', pycurl.FORM_FILE, 'file2.txt')),
('field3', (pycurl.FORM_CONTENTS, 'this is wei\000rd, but null-bytes are okay'))
]
c = pycurl.Curl()
c.setopt(c.URL, 'http://www.example.com')
c.setopt(c.HTTPPOST, fields)
c.perform()
c.close()
--------------------------------------------------
只提交文件
def upload_wav( wavfile, url=None, **kwargs ):
"""Upload a wav file to the server, return the response."""
class responseCallback:
"""Store the server response."""
def __init__(self):
self.contents=''
def body_callback(self, buf):
self.contents = self.contents + buf
def decode( self ):
self.contents = urllib.unquote(self.contents)
try:
self.contents = simplejson.loads(self.contents)
except:
return self.contents
t = responseCallback()
c = pycurl.Curl()
c.setopt(c.POST,1)
c.setopt(c.WRITEFUNCTION, t.body_callback)
c.setopt(c.URL,url)
postdict = [
('userfile',(c.FORM_FILE,open(wavfile, 'r').read())), #wav file to post
]
#If there are extra keyword args add them to the postdict
for key in kwargs:
postdict.append( (key,kwargs[key]) )
c.setopt(c.HTTPPOST,postdict)
c.setopt(c.VERBOSE,verbose)
c.perform()
c.close()
t.decode()
return t.contents
- pycurl 上传文件 提交
- 使用pycurl上传文件
- 如何在pycurl中上传文件
- 使用pycurl进行web提交
- 表单提交文件上传
- 提交表单上传文件
- libcurl提交表单上传文件
- 使用ajax提交上传文件
- HttpURLConnection 提交表单+ 上传文件
- libcurl提交表单上传文件
- Ajax表单提交上传文件
- Form提交,Ajax上传文件
- 文件上传,表单提交插件
- php上传文件--表单提交
- PycURL
- pycurl
- 如何使用Dojo提交上传文件请求
- 无刷新文件上传 ajax提交表单
- 程序与生活:为什么要工作?
- parasoft c++Test9.0破解
- 如何判断字符串是否为空串?string.length的优越性
- 在线分析和共享源代码
- 数组类模板
- pycurl 上传文件 提交
- LNK2005
- 找出所缺的整数
- LNK2001
- NSOperation和NSOperationQueue
- 第五周作业(一)
- LINQ 之 JOIN(2)
- 找感觉的第一个小程序
- 管家婆与盘点机应用解决方案