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

熱點內容
壓縮機型號v代表什麼 瀏覽:50
旅遊類源碼 瀏覽:860
電腦伺服器類型怎麼設置 瀏覽:228
pdf炒股 瀏覽:784
伺服器地址缺少埠號什麼意思 瀏覽:528
下載需要解壓的小說用哪個軟體 瀏覽:532
廣東分布式伺服器雲主機 瀏覽:581
伺服器忙打不開怎麼辦 瀏覽:13
tif壓縮軟體 瀏覽:411
程序員那麼可愛陸漓上班第1天 瀏覽:950
macbookair自帶什麼app 瀏覽:699
如何關了加密的軟體 瀏覽:581
程序員p2p待遇 瀏覽:922
ipd編譯要求 瀏覽:936
壓縮解壓王怎麼用 瀏覽:34
伺服器共享文件如何備份 瀏覽:758
買安卓手機怎麼在官網買 瀏覽:126
詩詞入門PDF 瀏覽:365
毒app是什麼單位 瀏覽:67
如何自己編譯android系統 瀏覽:796