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 6390721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:34:57+00:00 2026-05-25T03:34:57+00:00

I am using Apache HttpClient to connect to a server for downloading a .wav

  • 0

I am using Apache HttpClient to connect to a server for downloading a .wav file. I am using HTTP POST method in my program.

The server correctly responds with the following header and body:

> HTTP/1.1 200 OK\r\n Content-Disposition: attachment;
> filename=saveme1.mp3\r\n Content-Length: 6264\r\n
> Content-Transfer-Encoding: binary\r\n Content-Type: audio/mp3\r\n

How do I now extract the saveme1.mp3 file from the HTTP response? I am using the following code:

       ResponseHandler<String> responseHandler = new BasicResponseHandler();
       byte[] data = httpclient.execute(httppost, responseHandler).getBytes();

However, I am getting garbage when I am writing the data to a file.

FileOutputStream fileoutputstream = new FileOutputStream(outputFile);
for (int i = 0; i < data.length; i++) 
        fileoutputstream.write(data[i]);
  • 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-25T03:34:58+00:00Added an answer on May 25, 2026 at 3:34 am

    You are getting MIME attachment that you need to parse first. The BasicResponseHandler just return the response string, but you need the body of the attachment that contains the binary of your .mp3. You would need to do the following steps:

    • Understand the MIME format. You could skim the Wikipedia Entry for gaining quick familiarity
    • Once you understood, you need to create a MIME Parser. This would basically extract each part of the MIME message especially the body of your attachment. I think there should be something out there that you could reuse. You probably should look MimeMultipart. The only thing that I am not sure about it is whether it handles “binary” encoding in your message.
    • Create your own extension of ResponseHandler that will utilize the MIME Parser that you have in the previous step
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect to a secure server using Apache Commons HttpClient 3.1
I am using Apache HttpClient and would like to communicate HTTP errors (400 Bad
I am using Apache Axis to connect my Java app to a web server.
I am using Apache HttpClient to upload a file through MultipartEntity, I need to
I have multiple network interface(Like WIFI,LAN,LTE dougle).I am sending http request using apache httpclient
I'm trying to add a referer to an http post in Apache HttpClient (httpclient-4.0-beta2).
I'm using Apache Commons HttpClient to grab some data from a server. My problem
Using HttpClient 4.1.0, we're trying to connect to a remote server that normally would
I am attempting to connect to a local HTTPS server using the apache DefaultHttpClient
I am trying to post some JSON to a rest service using Apache Httpclient.

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.