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

熱點內容
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
安卓手機如何打開mark2文件 瀏覽:662
紅米手機解壓中文解壓密碼 瀏覽:316
安卓智謀三國志是什麼平台 瀏覽:948
伺服器系統linux怎麼下載 瀏覽:946
程序員面試寶典6 瀏覽:558