1

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?

4
  • 1
    To handle HTTP post on server you need a servlet, you could make a request from simple java using HttpUrlConnection Commented 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 :) Commented Jun 14, 2012 at 6:42
  • stackoverflow.com/questions/11011132/multipart-http-request/… Commented Jun 14, 2012 at 6:44
  • check my answer on above link. it may help u Commented Jun 14, 2012 at 6:44

5 Answers 5

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1

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 :)

Apache Commons

Comments

1

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.