導航:首頁 > 編程語言 > 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相關的資料

熱點內容
潛行者電影在線觀看 瀏覽:865
php判斷元素在數組中 瀏覽:745
androidphpmd5 瀏覽:691
vr能看什麼電影 瀏覽:163
成龍電影裡面有個龍復活了 瀏覽:106
成人影視免費 瀏覽:369
男的送快遞,女的在按摩的上班的叫什麼電影 瀏覽:753
海綿寶寶大電影免費中文版 瀏覽:276
愛國戰爭片免費觀看 瀏覽:888
三位數碼管單片機是如何工作的 瀏覽:728
免費看不下載老電影院 瀏覽:512
啄木鳥影業都有哪些作品 瀏覽:824
在電腦上怎麼把pdf保存成圖片 瀏覽:767
末段愛情廣播劇是哪個app可以聽 瀏覽:322
e片免費看 瀏覽:361
成龍教外國小孩功夫電影叫什麼 瀏覽:482
disk命令分區 瀏覽:912
丁巴度愛與激情 瀏覽:264
韓國野戰電影 瀏覽:462
法國chouchou在線觀看 瀏覽:700