导航:首页 > 编程语言 > python怎么获得mimetype

python怎么获得mimetype

发布时间:2023-03-20 23:04:28

㈠ 怎么用http上传一个文件到服务器 python

首先,标准HTTP协议对上传文件等表单的定义在这里:wwwietforg/rfc/rfc1867txt 大概数据包格式如下:

单文件:

Content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="field1"

Joe Blow
--AaB03x
content-disposition: form-data; name="pics"; filename="file1.txt"
Content-Type: text/plain

... contents of file1.txt ...
--AaB03x--
多文件:

Content-type: multipart/form-data, boundary=AaB03x

--AaB03x
content-disposition: form-data; name="field1"

Joe Blow
--AaB03x
content-disposition: form-data; name="pics"
Content-type: multipart/mixed, boundary=BbC04y

--BbC04y
Content-disposition: attachment; filename="file1.txt"
其次,python上传文件的几种方法:

1 自己封装HTTP的POST数据包:http//stackoverflowcom/questions/680305/using-multipartposthandler-to-post-form-data-with-python

import httplibimport mimetypesdef post_multipart(host, selector, fields, files): content_type, body = encode_multipart_formdata(fields, files) h = httplib.HTTP(host) h.putrequest('POST', selector) h.putheader('content-type', content_type) h.putheader('content-length', str(len(body))) h.endheaders() h.send(body) errcode, errmsg, headers = h.getreply() return h.file.read() def encode_multipart_formdata(fields, files): LIMIT = '----------lImIt_of_THE_fIle_eW_$' CRLF = '\r\n' L = [] for (key, value) in fields: L.append('--' + LIMIT) L.append('Content-Disposition: form-data; name="%s"' % key) L.append('') L.append(value) for (key, filename, value) in files:

阅读全文

与python怎么获得mimetype相关的资料

热点内容
51单片机晶码管 浏览:281
怎么查服务器假死原因日志在哪看 浏览:277
扫描pdf文件 浏览:926
解压密码百度云在线解压 浏览:767
传播学算法推荐 浏览:749
我的世界网络游戏如何查找服务器 浏览:257
安卓和苹果通讯录怎么互传 浏览:203
怎么打开隐私与应用加密的菜单 浏览:416
我的世界服务器小游戏的地址大全 浏览:578
在网络安全中加密安全机制提供了数据的 浏览:249
南京前端程序员私活怎么收费 浏览:981
拓扑pdf 浏览:440
如何在工行app查我的订单 浏览:214
车压缩机改电动 浏览:83
如何寻找音乐app 浏览:831
一加加密的照片 浏览:200
阿里云虚拟主机php 浏览:639
不卡点的解压视频 浏览:391
hex文件下载单片机 浏览:873
实现编译器的自展技术 浏览:655