1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| public void test() throws FileNotFoundException, IOException {
File file = new File("/home/firone/tmp/Rapport.pdf");
//File file = new File("/home/firone/mnt/Mon onclde charlie/Mon oncle Charlie - [6x04] - .avi");
final PostMethod pm = new PostMethod("http://firone.firone-land.com/utils/testFile.php");
ArrayList<Part> arrayList = new ArrayList<Part>();
arrayList.add(new StringPart("hihi", "plop"));
arrayList.add(new FilePart2("test", file));
MultipartRequestEntity mre = new MultipartRequestEntity(arrayList.toArray(new Part[]{}), pm.getParams());
pm.setRequestEntity(mre);
final HttpClient hc = new HttpClient();
//OutputStream requestOutputStream = new HttpConnection(hc.getHostConfiguration()).getRequestOutputStream();
System.out.println("5");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
System.out.println("123");
hc.executeMethod(pm);
System.out.println(pm.getResponseBodyAsString());
System.out.println("234");
} catch (IOException ex) {
Logger.getLogger(HosterFironeTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
thread.start();
System.out.println("1");
//OutputStream requestOutputStream = hc.getHttpConnectionManager().getConnection(hc.getHostConfiguration()).getRequestOutputStream();
try {
thread.join();
} catch (InterruptedException ex) {
Logger.getLogger(HosterFironeTest.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("2");
} |
Partager