multipart/form-data

仕事上でいろいろ問題が出たので調べた。
以下メンバーに送ったメールを抜粋。

各パートはバウンダリ文字で区切られている必要があります。
また、最後のバウンダリ文字列の後ろには終端記号「--」が必要です。
例:
Content-Type: multipart/form-data; boundary=バウンダリ文字列CRLF
--バウンダリ文字CRLF
第1パートCRLF
--バウンダリ文字CRLF
第2パートCRLF
--バウンダリ文字CRLF
第3パートCRLF
--バウンダリ文字--

各パートはヘッダとボディから構成されます。
ヘッダは下記のような種類があります。
・inputタグのフィールド名
Content-Disposition: form-data; name="fieldname"CRLF
・ボディのコンテントタイプ
Content-Type: application/octet-streamCRLF

例えば
<input type="text" name="fieldname" value="12345">
というフォームからデータが送られてきた場合は、

Content-Type: multipart/form-data; boundary=[boundarystring]CRLF
--[boundarystring]CRLF
Content-Disposition: form-data; name="fieldname"CRLF
12345CRLF
--[boundarystring]--

となります。

またcommons-fileuploadを用いる場合は、下記ヘッダがないと読み飛ばされます。

Content-Disposition: form-data; name="fieldname"CRLF

違ってたらごめんなさい。