Advertisement
kemkriszt

Http

Oct 16th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. //imports
  2. public class Sender extends JFrame {
  3.    
  4.     //code, code, and more code...
  5.     private void uploadData() throws Exception{
  6.        
  7.         httppost = new HttpPost("http://localhost/admin/upload.php");
  8.         MultipartEntity mpEntity = new MultipartEntity();
  9.         ContentBody cbFile = new FileBody(file, "image/jpg");
  10.         mpEntity.addPart("file", cbFile);
  11.         mpEntity.addPart("name",new StringBody(title));
  12.         mpEntity.addPart("material",new StringBody(mat));
  13.         mpEntity.addPart("marime",new StringBody(dimens));
  14.         mpEntity.addPart("pret",new StringBody(pret));
  15.         mpEntity.addPart("categorie",new StringBody(cat));
  16.         httppost.setEntity(mpEntity);
  17.        
  18.         System.out.println("executing request " + httppost.getRequestLine());
  19.         HttpResponse response = client.execute(httppost);
  20.         HttpEntity resEntity = response.getEntity();
  21.        
  22.        
  23.         System.out.println(response.getStatusLine());
  24.         if (resEntity!=null) {
  25.             System.out.println("Succes");
  26.             File f = new File("output.html");
  27.             PrintWriter pw = new PrintWriter(f);
  28.             pw.println(EntityUtils.toString(resEntity));
  29.             pw.close();
  30.         }else{
  31.             new Error("Error");
  32.         }
  33.         if (resEntity != null) {
  34.             resEntity.consumeContent();
  35.         }
  36.  
  37.         client.getConnectionManager().shutdown();
  38.         dispose();
  39.     }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement