导航:首页 > 编程语言 > 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相关的资料

热点内容
为什么程序员拿了股份还要高薪 浏览:946
电脑运行命令里的记录能删吗 浏览:697
linuxwss 浏览:848
一个软件需要登录服务器地址 浏览:923
哪里有解压程序 浏览:299
java静态方法内存 浏览:545
我的世界ec服务器如何带vip 浏览:737
什么是由解析器域名和服务器构成 浏览:414
自动识别电影信息源码 浏览:849
柱筋箍筋加密区怎么算 浏览:48
钢筋中加密15倍是什么意思 浏览:366
esc加密算法 浏览:518
linux运行exe命令 浏览:124
一级建造师管理pdf 浏览:720
如何更改服务器登录账号 浏览:317
看pdf文件软件 浏览:183
android恢复模式 浏览:808
生命令人忧 浏览:597
魔兽搬砖怎么选择服务器 浏览:771
程序员求伯君图片 浏览:827