Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //imports
- public class Sender extends JFrame {
- //code, code, and more code...
- private void uploadData() throws Exception{
- httppost = new HttpPost("http://localhost/admin/upload.php");
- MultipartEntity mpEntity = new MultipartEntity();
- ContentBody cbFile = new FileBody(file, "image/jpg");
- mpEntity.addPart("file", cbFile);
- mpEntity.addPart("name",new StringBody(title));
- mpEntity.addPart("material",new StringBody(mat));
- mpEntity.addPart("marime",new StringBody(dimens));
- mpEntity.addPart("pret",new StringBody(pret));
- mpEntity.addPart("categorie",new StringBody(cat));
- httppost.setEntity(mpEntity);
- System.out.println("executing request " + httppost.getRequestLine());
- HttpResponse response = client.execute(httppost);
- HttpEntity resEntity = response.getEntity();
- System.out.println(response.getStatusLine());
- if (resEntity!=null) {
- System.out.println("Succes");
- File f = new File("output.html");
- PrintWriter pw = new PrintWriter(f);
- pw.println(EntityUtils.toString(resEntity));
- pw.close();
- }else{
- new Error("Error");
- }
- if (resEntity != null) {
- resEntity.consumeContent();
- }
- client.getConnectionManager().shutdown();
- dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement