Development Features:
Web front-end submission upload file, a server receive, forwarding to B server for file processing
The following is a simple implementation of the code, the specifics of the optimization of the fundamental requirements of their own changes.
PublicString Handleresponse (httpservletrequest request, httpservletresponse response) throws Unsupportedencodingexcep tion, IOException {String method = Request.getmethod ();String URL ="B-Server API URL";if (Method.equals ("POST")) {string contentType = "Application/json; Charset=utf-8 "; if (Request.getcontenttype ()! = null) ContentType = Request.getcontenttype (); //gets the null pointer map<string, string[]> tmp = new HashMap (Request.getparametermap ()); if (Contenttype.tolowercase (). StartsWith ( "multipart/")) { Multiparthttpservletrequest multipartrequest = webutils.getnativerequest (Request, Multiparthttpservletrequest.class); Multipartfile file = multipartrequest.getfile ( "file"); return httpclientupload (URL, file, tmp);} } return null;}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
Public StringHttpclientupload (String URL, multipartfile file, map<string, string[]>params) throws Clientprotocolexception, IOException {HttpClient HttpClient =New Defaulthttpclient ();Request Processing page HttpPost HttpPost =New HttpPost (URL);Create the file to be processed String fileName = File.getoriginalfilename (); Contentbody files =New Bytearraybody (File.getbytes (), fileName);Populate the requested form field multipartentity reqentity =New Multipartentity (); Reqentity.addpart ("File", files);if (Params! =NULL) {Here's a cursory treatment of values[]For (String key:Params.keyset ()) {string[] values =Params.Get (key);for (int i =0; i < values.length; i++) {StringValue = Values[i];try {value = Urlencoder.encode ( Value, "UTF-8"); Reqentity.addpart (Key, new stringbody (value));} catch (unsupportedencodingexception e) {//TODO auto-generated Catch block E.printstacktrace (); }}}} //set request Httppost.setentity (reqentity); //execute httpresponse response = Httpclient.execute (HttpPost); if (Httpstatus.sc_ok = Response.getstatusline (). Getstatuscode ()) {HttpEntity entity = Response.getentity (); return entityutils.tostring (Entity, Charset.forname ( "UTF-8" )); } return null;}
1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- Ten
- one
- 2
- (
- )
- +
- +
- /
- 0
- +
- all
- +
- +
- +
- -
- 29
- +
- +
- +
- ,
- ,
- ,
- , PNS
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
http://bbs.bxzc123.com/forum.php?mod=viewthread&tid=244545
http://bbs.bxzc123.com/forum.php?mod=viewthread&tid=244541
http://bbs.bxzc123.com/forum.php?mod=viewthread&tid=244538
http://bbs.bxzc123.com/forum.php?mod=viewthread&tid=244527
http://bbs.bxzc123.com/forum.php?mod=viewthread&tid=244528
http://bbs.bxzc123.com/forum.php?mod=viewthread&tid=244529
http://bbs.bxzc123.com/forum.php?mod=viewthread&tid=244530
httpclient Implement file Upload Relay