Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////DATA RECEIVED
- POST /mobile-image/ProcessRequest HTTP/1.1
- Content-Length: 921897
- Content-Type: multipart/form-data; boundary=ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
- Host: 192.168.1.167:8080
- Connection: Keep-Alive
- --ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
- Content-Disposition: form-data; name="text"
- Content-Type: text/plain; charset=US-ASCII
- Content-Transfer-Encoding: 8bit
- test text
- --ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
- Content-Disposition: form-data; name="image"; filename="image"
- Content-Type: application/octet-stream
- Content-Transfer-Encoding: binary
- [image-data-here]
- --ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01--
- //////ANDROID CLIENT CODE
- HttpPost httpPost = new HttpPost(mURI);
- MultipartEntity requestEntity = new MultipartEntity();
- requestEntity.addPart("text", new StringBody("test text"));
- requestEntity.addPart("image", new ByteArrayBody(mImage, "image"));
- httpPost.setEntity(requestEntity);
- HttpResponse httpResponse = mHttpClient.execute(httpPost);
- //////SERVLET
- @Override
- public void doPost(HttpServletRequest request, HttpServletResponse response) {
- try {
- response.setContentType("text/html");
- PrintWriter out = response.getWriter();
- File file = new File(getServletContext().getRealPath("/") + File.separator + "WEB-INF" + File.separator + "sms-mobile-image.jpg");
- file.createNewFile();
- Writer outfile = new OutputStreamWriter(new FileOutputStream(file));
- List<Part> formData = new ArrayList(request.getParts());
- if(formData.size()>0)
- System.out.println(formData.get(0).getName());
- else
- System.out.println("no form data found");
- } catch(Exception e) {
- System.out.println(e.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement