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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:23:49+00:00 2026-05-15T11:23:49+00:00

EDIT : I am trying to send an xml file as a post request

  • 0

EDIT :

I am trying to send an xml file as a post request in Android.

The server accepts text/xml. I tried creating a MultipartEntity, which has a content type of multipart/form-data.

 HttpClient httpClient = new DefaultHttpClient();

    /* New Post Request */
    HttpPost postRequest = new HttpPost(url);

    byte[] data = IOUtils.toByteArray(payload);

    /* Body of the Request */
     InputStreamBody isb = new InputStreamBody(new ByteArrayInputStream(data), "uploadedFile");
    MultipartEntity multipartContent = new MultipartEntity();
    multipartContent.addPart("uploadedFile", isb);

    /* Set the Body of the Request */
    postRequest.setEntity(multipartContent);

    /* Set Authorization Header */
    postRequest.setHeader("Authorization", authHeader);
    HttpResponse response = httpClient.execute(postRequest);
    InputStream content = response.getEntity().getContent();
    return content;

However I get an error saying the content type cannot be consumed.

The server refused this request because the request entity is in a format not supported by the requested resource for the requested method (Cannot consume content type).

How do I change the content type of the request?

Edit:

  • 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-15T11:23:49+00:00Added an answer on May 15, 2026 at 11:23 am

    Long story short – use another constructor for your InputStreamBody that lets you specify the mime type you wish to use. If you don’t, the parts in your multipart request will not have a Content-Type specified (see below for details). Consequently, the server does not know what type the file is, and in your case might be refusing to accept it (mine accepted them anyway, but I assume this is driven by config). If this still doesn’t work, you might have a server-side issue.

    Note: Changing the Content-Type of the request itself to anything but multipart/form-data; boundary=someBoundary renders the request invalid; the server will not correctly parse the multipart parts.

    Long story long – here’s my findings.

    Given the following code:

    byte[] data = "<someXml />".getBytes();
    multipartContent.addPart("uploadedFile", new InputStreamBody(new ByteArrayInputStream(data), "text/xml", "somefile.xml"));
    multipartContent.addPart("otherPart", new StringBody("bar", "text/plain", Charset.forName("UTF-8")));
    multipartContent.addPart("foo", new FileBody(new File("c:\\foo.txt"), "text/plain"));
    

    The HttpClient posts the following payload (captured w/ Wireshark):

    POST /upload.php HTTP/1.1
    Transfer-Encoding: chunked
    Content-Type: multipart/form-data; boundary=SeXc6P2_uEGZz9jJG95v2FnK5a8ozU8KfbFYw3
    Host: thehost.com
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1-alpha2 (java 1.5)
    
    --SeXc6P2_uEGZz9jJG95v2FnK5a8ozU8KfbFYw3
    Content-Disposition: form-data; name="uploadedFile"; filename="someXml.xml"
    Content-Type: text/xml
    Content-Transfer-Encoding: binary
    
    <someXml />
    --SeXc6P2_uEGZz9jJG95v2FnK5a8ozU8KfbFYw3
    Content-Disposition: form-data; name="otherPart"
    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    
    yo
    --SeXc6P2_uEGZz9jJG95v2FnK5a8ozU8KfbFYw3
    Content-Disposition: form-data; name="foo"; filename="foo.txt"
    Content-Type: text/plain
    Content-Transfer-Encoding: binary
    
    Contents of foo.txt
    
    --SeXc6P2_uEGZz9jJG95v2FnK5a8ozU8KfbFYw3--
    

    On the server, the following PHP script:

    <?php
    print_r($_FILES);
    print_r($_REQUEST);
    

    spitted out the following:

    Array
    (
        [uploadedFile] => Array
            (
                [name] => someXml.xml
                [type] => text/xml
                [tmp_name] => /tmp/php_uploads/phphONLo3
                [error] => 0
                [size] => 11
            )
    
        [foo] => Array
            (
                [name] => foo.txt
                [type] => text/plain
                [tmp_name] => /tmp/php_uploads/php58DEpA
                [error] => 0
                [size] => 21
            )
    
    )
    Array
    (
        [otherPart] => yo
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to send simple login/password parameters to my PHP file in my server
I'm trying to send a POST request to a web app. I'm using the
I am trying to send data to a web server using a post, this
I'm trying to edit the httpd.conf file located in /private/etc/apache2, and I can't figure
I'm trying to test if the xml file have the tag <group> var xmlhttp
I am trying to display, edit with validation an object which is stored in
I am trying to send POST data from a python script to a url.
I have a XML which works with an XSLT file that transforms the XML
I'm trying to send an http get request via the httplib, but I'm facing
I am trying to use Javascript to transform part of a XML file to

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.