I did research and I cant find a good tutorial to post a file with http. Do I have to do a servlet to make the http post or can it be done just with java?
-
1To handle HTTP post on server you need a servlet, you could make a request from simple java using HttpUrlConnection – jmj Jun 14 '12 at 06:34
-
Thanks @JigarJoshi. I just want to upload the files to a localhost, then download the files from the same localhost. I want to measure the time it takes to read/write. I will research about HttpUrlConnection :) – AndreS Jun 14 '12 at 06:42
-
http://stackoverflow.com/questions/11011132/multipart-http-request/11011268#11011268 – Alpesh Prajapati Jun 14 '12 at 06:44
-
check my answer on above link. it may help u – Alpesh Prajapati Jun 14 '12 at 06:44
5 Answers
to make http post no need of servlet, you can do it using HttpClient library
check
How to upload a file using Java HttpClient library working with PHP
you definitively need a servlet to handle a post request in server side

- 1
- 1

- 10,870
- 3
- 37
- 42
You can use the FileUpload library from Apache: http://commons.apache.org/fileupload/
A good tutorial to start is this http://www.adictosaltrabajo.com/tutoriales/tutoriales.php?pagina=fileupload
Regards

- 658
- 5
- 12
You can use the Apache Commons FileUpload library. That should help you with handling the file upload and storing the file, so you can write less code :)

- 2,462
- 15
- 29
A client can probably perform the post of the file, however you won't be able to test it without some server application waiting for it. You can make it in a servlet or use something like WampServer if you know php, the important thing is for something to be listening for your post.

- 66
- 4
You need two pieces of software: a HTTP client and a HTTP server. You may use Java to implement both, but, depending on your operating system, it may be easier to use PHP on the server side. I wrote a blog post some time ago to POST data to a PHP script which may be useful. It show how to send a file and arbitrary data at a time: the key is multipart/form-data
as the MIME type of the request. It also demonstrates how to send data so on the PHP side it's arranged like an array.

- 20,627
- 6
- 47
- 86