Not much nonsense. There is a code directly!
1 package httpclient; 2 3 Import Java. io. file; 4 Import Java. NIO. charset. charset; 5 6 Import Org. apache. HTTP. consts; 7 Import Org. apache. HTTP. header; 8 Import Org. apache. HTTP. httpentity; 9 Import Org. apache. HTTP. client. methods. closeablehttpresponse; 10 Import Org. apache. HTTP. client. methods. httppost; 11 import Org. apache. HTTP. entity. contenttype; 12 Import Org. apache. HTTP. entity. mime. httpmultipartmode; 1 3 Import Org. apache. HTTP. entity. mime. multipartentitybuilder; 14 Import Org. apache. HTTP. entity. mime. content. filebody; 15 Import Org. apache. HTTP. entity. mime. content. stringbody; 16 Import Org. apache. HTTP. impl. client. closeablehttpclient; 17 import Org. apache. HTTP. impl. client. httpclients; 18 Import Org. apache. HTTP. util. charsetutils; 19 Import Org. apache. HTTP. util. entityutils; 20 21 public class httpdemo {22 p Ublic static void main (string [] ARGs) throws exception {23 closeablehttpclient httpclient = httpclients. createdefault (); 24 try {25 httppost = new httppost ("http: // localhost: 28080" 26 + "/PM/restful/trip/saveptriprecord "); 27 28 // filebody bin = // new filebody (new file ("D: // tree .jpg"); 29 file = new file ("D: // tree .jpg "); 30 filebody bin = new filebody (File); 31 // plain text userid = New stringbody (33 "f39d2a3e466b292b01466f2388900020", contenttype. create (34 "text/plain", consts. utf_8); 35 stringbody startdate = new stringbody ("2014-8-1 09:13:12", 36 contenttype. create ("text/plain", consts. utf_8); 37 stringbody enddate = new stringbody ("2014-8-1 09:13:12", 38 contenttype. create ("text/plain", consts. utf_8); 39 stringbody triptime = new stringbody ("6.8", contenttype. create (40 "te XT/plain ", consts. utf_8); 41 stringbody tripaddress = new stringbody ("what", contenttype. create (42 "text/plain", consts. utf_8); 43 stringbody tripresons = new stringbody ("what", contenttype. create (44 "text/plain", consts. utf_8); 45 httpentity reqentity = multipartentitybuilder. create () 46. setmode (httpmultipartmode. browser_compatible) // sets it to compatible with the memory generator mode 47. setcharset (charsetutils. get ("utf8") // set limit to 48. addpa RT ("userid", userid ). addpart ("startdate", startdate) 49. addpart ("enddate", enddate ). addpart ("triptime", triptime) 50. addpart ("tripaddress", tripaddress) 51. addpart ("tripresons", tripresons ). addpart ("bin", BIN) 52. build (); 53 54 httppost. setentity (reqentity); 55 system. out56. println ("executing request" + httppost. getrequestline (); 57 closeablehttpresponse response = httpclient.exe cute (httppost); 58 Try {59 system. out. println ("--------------------------------------"); 60 system. out. println (response. getstatusline (); 61 httpentity resentity = response. getentity (); 62 if (resentity! = NULL) {63 system. out. println ("response Content Length:" 64 + resentity. getcontentlength (); 65} 66 system. out. println (entityutils. tostring (resentity, 67 charset. forname ("UTF-8"); 68 entityutils. consume (resentity); 69} finally {70 response. close (); 71} 72} finally {73 httpclient. close (); 74} 75} 76 77}