Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7568643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:58:37+00:00 2026-05-30T14:58:37+00:00

I am using a Java server that exposes a RESTful API on the following

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:58:38+00:00Added an answer on May 30, 2026 at 2:58 pm

    I believe this is more-or-less equivalent using Java and httpclient-4.x:

    try {
        Credentials credentials = new UsernamePasswordCredentials("admin", "password");  //-u admin:password
        DefaultHttpClient httpClient = new DefaultHttpClient();
        httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
        HttpPut put = new HttpPut("http://localhost:8080/my-server/file.ext");  //-X PUT
        put.setEntity(new FileEntity(new File("/absolute/path/file/to/upload/file.ext"), "image/png"));  //@ - absolute path
        httpClient.execute(put);
    } catch(Exception e) {
        //-f, fail silently
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a server that performs non-blocking IO using the Java NIO API.
I'm using Java for accessing Alfresco content server via it's web service API for
I wrote a simple client/server in java that transfers files using java NIO Socketchannel.
I have a string in a Java server application that is accessed using AJAX.
I made a custom http server using java. It runs properly on XP machines
I have a java server that serve many clients using Sockets In case of
We have a medium sized Java server that has data flowing in the following
I'm using Java to create a client/server application that communicates using TCP. The network
I'm currently developing a server (using Java) that has to send quite often (every
I have to write a multithreaded client and server using Java's socket api. Both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.