Advertisement
meccharef

Untitled

Apr 28th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1.   private void uploadFile(String filePath) {
  2.         try {
  3.             try {
  4.  
  5.                 HttpPost httpost = new HttpPost(url_upload);
  6.                 MultipartEntity entity = new MultipartEntity();
  7.                 entity.addPart("Mdp", new StringBody(URLEncoder.encode(mdp)));
  8.                 entity.addPart("Msg", new StringBody(URLEncoder.encode(msg)));
  9.                 entity.addPart("type", new StringBody(type));
  10.                 if(type.equals("1")) {
  11.                     entity.addPart("Emailm", new StringBody(URLEncoder.encode(email)));
  12.                     entity.addPart("Emailp", new StringBody(URLEncoder.encode(emaildest)));
  13.  
  14.                 }else {
  15.  
  16.                     entity.addPart("Emailp", new StringBody(URLEncoder.encode(email)));
  17.                     entity.addPart("Emailm", new StringBody(URLEncoder.encode(emaildest)));
  18.                 }
  19.                 if (attach){
  20.                     entity.addPart("attachement", new FileBody(new File(filePath)));
  21.                     entity.addPart("attacher", new StringBody("oui"));
  22.                 }else{
  23.                     entity.addPart("attacher", new StringBody("non"));
  24.                 }
  25.  
  26.                 httpost.setEntity(entity);
  27.  
  28.                 HttpResponse response;
  29.                 HttpClient httpclient = new DefaultHttpClient();
  30.                 response = httpclient.execute(httpost);
  31.  
  32.                 if (response != null) {
  33.                     HttpEntity entity2 = response.getEntity();
  34.                     String responseString = EntityUtils.toString(entity2, "UTF-8");
  35.                     System.out.println(responseString);
  36.                      json2=new JSONObject(responseString);
  37.  
  38.                 } else { //erreur
  39.                 }
  40.             } catch (IOException e) {
  41.                 e.printStackTrace();
  42.             }
  43.         }catch (Exception e){
  44.  
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement