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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:28:41+00:00 2026-05-31T03:28:41+00:00

i’m trying to send an http request from an Android app to a Java

  • 0

i’m trying to send an http request from an Android app to a Java Servlet hosted with Tomcat. the app would send some text and image data to the servlet, but the servlet does not seem to see the multipart form data. i’ve had a little direction from this tutorial as well as some IRC help with confirming the incoming data: http://blog.tacticalnuclearstrike.com/2010/01/using-multipartentity-in-android-applications/

Android code:
////libs: httpclient-4.1.3, httpcore-4.1.4, httpmime-4.1.3, apache-mime4j-core-0.7.2

HttpPost httpPost = new HttpPost(mURI);
MultipartEntity requestEntity = new MultipartEntity();
requestEntity.addPart("text", new StringBody("test text"));
requestEntity.addPart("image", new ByteArrayBody(mImage, "image"));
httpPost.setEntity(requestEntity);
HttpResponse httpResponse = mHttpClient.execute(httpPost);

servlet code:

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) {
    try {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        File file = new File(getServletContext().getRealPath("/") + File.separator + "WEB-INF" + File.separator + "sms-mobile-image.jpg");
        file.createNewFile();
        Writer outfile = new OutputStreamWriter(new FileOutputStream(file));
        List<Part> formData = new ArrayList(request.getParts());
        if(formData.size()>0)
            System.out.println(formData.get(0).getName());
        else
            System.out.println("no form data found");
    } catch(Exception e) {
        System.out.println(e.toString());
    }
}

Actual data sent (confirmed with wireshark):

POST /mobile-image/ProcessRequest HTTP/1.1
Content-Length: 921897
Content-Type: multipart/form-data; boundary=ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
Host: 192.168.1.167:8080
Connection: Keep-Alive

--ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
Content-Disposition: form-data; name="text"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit

test text
--ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01
Content-Disposition: form-data; name="image"; filename="image"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

[image-data-here]
--ZiB5ibYqpxux_mP6HeswY9B__17vOLCVvay01--

output:

no form data found

it was suggested that i look through the web.xml config, so that’ll be my next step, but i feel at a loss here. isn’t this the way it’s supposed to work?

  • 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-31T03:28:42+00:00Added an answer on May 31, 2026 at 3:28 am

    i was able to solve this by using the com.oreilly.servlet package. it’s a shame though, i still think i may be doing something wrong. this seems like something that should be built into the httpclient library… regardless, if you’re interested, there are plenty of examples that make use of this library and the one i followed is here:
    http://www.jguru.com/faq/view.jsp?EID=1045507

    posted in srinivas’ reply somewhere down the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.