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

熱點內容
反編譯了別人的app會被發現嗎 瀏覽:918
上海光裕汽車壓縮機有限公司 瀏覽:332
連接ps4伺服器地址 瀏覽:136
新神魔大陸三星賬號是什麼伺服器 瀏覽:677
壓縮機lj100cy 瀏覽:556
王者系統怎麼轉回安卓系統 瀏覽:749
linux查看路由表命令 瀏覽:506
高手程序員使用什麼筆記本 瀏覽:440
ios壓縮圖片app 瀏覽:839
排隊論pdf 瀏覽:520
python調用無參函數 瀏覽:799
主管開除女程序員 瀏覽:713
雲伺服器轉售 瀏覽:541
壓縮空氣漏氣量怎樣計算 瀏覽:103
手機app是怎麼跳轉的 瀏覽:664
學編程的重要性 瀏覽:25
程序員去按摩 瀏覽:740
奧迪手機控車app怎麼添加愛車 瀏覽:5
收磚機石獅編程培訓廠家 瀏覽:762
吉里吉里2安卓模擬器怎麼用 瀏覽:819