Advertisement
moonlightcheese

Untitled

Mar 6th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. //////DATA RECEIVED
  2. POST /mobile-image/ProcessRequest HTTP/1.1
  3. Content-Length: 921897
  4. Content-Type: multipart/form-data; boundary=ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
  5. Host: 192.168.1.167:8080
  6. Connection: Keep-Alive
  7.  
  8. --ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
  9. Content-Disposition: form-data; name="text"
  10. Content-Type: text/plain; charset=US-ASCII
  11. Content-Transfer-Encoding: 8bit
  12.  
  13. test text
  14. --ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
  15. Content-Disposition: form-data; name="image"; filename="image"
  16. Content-Type: application/octet-stream
  17. Content-Transfer-Encoding: binary
  18.  
  19. [image-data-here]
  20. --ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01--
  21.  
  22.  
  23. //////ANDROID CLIENT CODE
  24. HttpPost httpPost = new HttpPost(mURI);
  25. MultipartEntity requestEntity = new MultipartEntity();
  26. requestEntity.addPart("text", new StringBody("test text"));
  27. requestEntity.addPart("image", new ByteArrayBody(mImage, "image"));
  28. httpPost.setEntity(requestEntity);
  29. HttpResponse httpResponse = mHttpClient.execute(httpPost);
  30.  
  31.  
  32. //////SERVLET
  33. @Override
  34. public void doPost(HttpServletRequest request, HttpServletResponse response) {
  35.     try {
  36.         response.setContentType("text/html");
  37.         PrintWriter out = response.getWriter();
  38.        
  39.         File file = new File(getServletContext().getRealPath("/") + File.separator + "WEB-INF" + File.separator + "sms-mobile-image.jpg");
  40.         file.createNewFile();
  41.         Writer outfile = new OutputStreamWriter(new FileOutputStream(file));
  42.         List<Part> formData = new ArrayList(request.getParts());
  43.         if(formData.size()>0)
  44.             System.out.println(formData.get(0).getName());
  45.         else
  46.             System.out.println("no form data found");
  47.     } catch(Exception e) {
  48.         System.out.println(e.toString());
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement