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 HttpUrlConnectionJigar Joshi– Jigar Joshi2012-06-14 06:34:07 +00:00Commented Jun 14, 2012 at 6: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– AndreS2012-06-14 06:42:53 +00:00Commented Jun 14, 2012 at 6:42
-
stackoverflow.com/questions/11011132/multipart-http-request/…Alpesh Prajapati– Alpesh Prajapati2012-06-14 06:44:06 +00:00Commented Jun 14, 2012 at 6:44
-
check my answer on above link. it may help uAlpesh Prajapati– Alpesh Prajapati2012-06-14 06:44:44 +00:00Commented Jun 14, 2012 at 6: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
Comments
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
Comments
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 :)
Comments
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.