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

  • Home
  • SEARCH
  • 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 6784623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:01:05+00:00 2026-05-26T17:01:05+00:00

I’m trying to post 2 fields, id and data, to a servlet using HttpClient.

  • 0

I’m trying to post 2 fields, id and data, to a servlet using HttpClient.
The problem is that if the length of the data field is less than 1MB or so, the servlet will get what I posted. But if the length of the data field is larger than 1MB or so, the servlet will receive null for all fields. What am I missing here? Thanks.

Here’s the sample data that I post to the servlet:

id=12312123123123

data=the content of a file that is base-64 encoded

Here’s the method that I use to post data to the servlet.

    private byte[] post(String aUrl,
                        Map<String,String> aParams,
                        String aCharsetEnc,
                        int aMaxWaitMs) throws Exception
{
    PostMethod post = null;
    try
    {
        HttpClient client = new HttpClient();
        post = new PostMethod(aUrl);
        post.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + aCharsetEnc);           
                   
        for (String key : aParams.keySet())
        {
            post.addParameter(key, aParams.get(key));
        }

        final int code = client.executeMethod(post);
        if (code == HttpStatus.SC_NO_CONTENT || code == HttpStatus.SC_NOT_FOUND)
        {
            return null;
        }
        else if (code != HttpStatus.SC_OK)
        {
            throw new HttpException("Error code " + code + " encountered.");
        }

        InputStream stream = post.getResponseBodyAsStream();
        if (stream != null)
        {
            return BlobHelper.readBytes(stream);
        }
        return null;
    }
    finally
    {
        if (post != null)
        {
            post.releaseConnection();
        }
    }
}

Here’s the method of the servlet.

public void doPost(HttpServletRequest aReq, HttpServletResponse aResp)
    throws ServletException, IOException
{
    setNoCache(aResp);
    aResp.setContentType("text/plain");

    try
    {
        final String id = aReq.getParameter(PARAM_ID);
        final String dataStr = aReq.getParameter(PARAM_DATA);


        if (log().isDebugEnabled())
        {
            log().debug("id=" + id);
            log().debug("data=" + dataStr);
        }
     }
     catch (Exception e)
     {
     }
}   
  • 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-26T17:01:06+00:00Added an answer on May 26, 2026 at 5:01 pm

    Usually servlet containers have a maximum post size parameter.

    For Tomcat you can follow the steps documented here(they should be similar for other appservers) –

    Is there a max size for POST parameter content?

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.