I am using a Java server that exposes a RESTful API on the following URL:
http://localhost:8080/my-server/
The docs recommend using curl
for submitting simple PUT
requests (file uploads), and strongly recommend users to use the exact same arguments as provided in the examples. All of the examples look like this:
curl -X PUT -f -u admin:password --data-binary @/absolute/path/file/to/upload/file.ext "http://localhost:8080/my-server/file.ext"
This server will not work with FTP or any other normal transfer protocol.
I found this question on SO where the answer-er recommended using java.net.URL
and its companion java.net.URLConnection
instead of trying to work with curl/libcurl.
I've never even ran a curl
command before, so I am asking anyone who knows both curl and Java if URL/URLConnection (or any other Java framework) can be used instead of curl for my specific problem here. If not, then I will have to write a component that executes commands from the local command-line/terminal, and then execute the above curl
command inside that component, and that just feels ugly/nasty.
If I can accomplish the same thing in a Java network API, I would prefer to do it that way.
And, if it can be done in Java, how would I use URL/URLConnection to set up the exact same command arguments as the example I provided? Specifically:
-X
PUT
-f
-u admin:password
--data-binary
-@absolute/path/...
Thanks in advance for any insight here or nudges in the right direction!