Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void uploadFile(String filePath) {
- try {
- try {
- HttpPost httpost = new HttpPost(url_upload);
- MultipartEntity entity = new MultipartEntity();
- entity.addPart("Mdp", new StringBody(URLEncoder.encode(mdp)));
- entity.addPart("Msg", new StringBody(URLEncoder.encode(msg)));
- entity.addPart("type", new StringBody(type));
- if(type.equals("1")) {
- entity.addPart("Emailm", new StringBody(URLEncoder.encode(email)));
- entity.addPart("Emailp", new StringBody(URLEncoder.encode(emaildest)));
- }else {
- entity.addPart("Emailp", new StringBody(URLEncoder.encode(email)));
- entity.addPart("Emailm", new StringBody(URLEncoder.encode(emaildest)));
- }
- if (attach){
- entity.addPart("attachement", new FileBody(new File(filePath)));
- entity.addPart("attacher", new StringBody("oui"));
- }else{
- entity.addPart("attacher", new StringBody("non"));
- }
- httpost.setEntity(entity);
- HttpResponse response;
- HttpClient httpclient = new DefaultHttpClient();
- response = httpclient.execute(httpost);
- if (response != null) {
- HttpEntity entity2 = response.getEntity();
- String responseString = EntityUtils.toString(entity2, "UTF-8");
- System.out.println(responseString);
- json2=new JSONObject(responseString);
- } else { //erreur
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }catch (Exception e){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement