package Ġguide . howto . use _ multipart _ forms Ċ Ċ import Ġorg . http 4 k . client . Apache Client Ċ import Ġorg . http 4 k . core . ContentType Ċ import Ġorg . http 4 k . core . Method . POST Ċ import Ġorg . http 4 k . core . Multipart Form Body Ċ import Ġorg . http 4 k . core . Request Ċ import Ġorg . http 4 k . core . Response Ċ import Ġorg . http 4 k . core . Status . Companion . OK Ċ import Ġorg . http 4 k . lens . Multipart FormField Ċ import Ġorg . http 4 k . lens . Multipart Form File Ċ import Ġorg . http 4 k . server . Sun Http Ċ import Ġorg . http 4 k . server . as Server Ċ Ċ fun Ġmain () Ġ{ ĊĊĠĠĠ Ġ// Ġextract Ġthe Ġbody Ġfrom Ġthe Ġrequest Ġand Ġthen Ġthe Ġfields / files Ġfrom Ġit ĊĠĠĠ Ġval Ġserver Ġ= Ġ{ Ġr : ĠRequest Ġ-> ĊĠĠĠĠĠĠĠ Ġval Ġreceived Form Ġ= ĠMultip art Form Body . from ( r ) ĊĠĠĠĠĠĠĠ Ġprintln ( received Form . field Values (" field ")) ĊĠĠĠĠĠĠĠ Ġprintln ( received Form . field (" field 2 ")) ĊĠĠĠĠĠĠĠ Ġprintln ( received Form . files (" file ")) ĊĊĠĠĠĠĠĠĠ ĠResponse ( OK ) ĊĠĠĠ Ġ}. as Server ( Sun Http ( 8 0 0 0 )). start () ĊĊĠĠĠ Ġ// Ġadd Ġfields Ġand Ġfiles Ġto Ġthe Ġmultipart Ġform Ġbody ĊĠĠĠ Ġval Ġbody Ġ= ĠMultip art Form Body () ĊĠĠĠĠĠĠĠ Ġ. plus (" field " Ġto Ġ" my - value ") ĊĠĠĠĠĠĠĠ Ġ. plus (" field 2 " Ġto ĠMultip art FormField (" my - value 2 ", ĠlistOf (" my - header " Ġto Ġ" my - value "))) ĊĠĠĠĠĠĠĠ Ġ. plus (" file " Ġto ĠMultip art Form File (" image . txt ", ĠContentType . OCT ET _ STREAM , Ġ" some binary content ". byte InputStream ())) ĊĊĠĠĠ Ġ// Ġwe Ġneed Ġto Ġset Ġboth Ġthe Ġbody ĠAND Ġthe Ġcorrect Ġcontent Ġtype Ġheader Ġon Ġthe Ġthe Ġrequest ĊĠĠĠ Ġval Ġrequest Ġ= ĠRequest ( POST , Ġ" http :// localhost : 8 0 0 0 ") ĊĠĠĠĠĠĠĠ Ġ. header (" content - type ", Ġ" multipart / form - data ; Ġboundary =${ body . boundary }") ĊĠĠĠĠĠĠĠ Ġ. body ( body ) ĊĊĠĠĠ Ġprintln ( Apache Client ()( request )) ĊĊĠĠĠ Ġserver . stop () Ċ } Ċ