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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:13:44+00:00 2026-05-27T08:13:44+00:00

I have just a curiosity question. I have an HttpPost request in Android that

  • 0

I have just a curiosity question. I have an HttpPost request in Android that looks something like this:

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(getString(R.string.url));

//This code does not work
HttpParams params = new BasicHttpParams();
params.setParameter("type", "20");
post.setParams(params);

try {
    HttpResponse response = client.execute(post);
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

On my server side, I have a servlet that listens for requests and parses the parameters:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Enumeration en = request.getParameterNames();
    while (en.hasMoreElements()){
        System.out.println(en.nextElement());
    }
} 

When I execute this code, the servlet does not see any parameters at all. But if I replace the whole “parameter” chunk with this code:

//This code works
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
nameValuePairs.add(new BasicNameValuePair("type", "20"));

try {
    post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
    e1.printStackTrace();
}

My servlet can parse parameters. It’s not a problem, I’m just going to use the entity but my question is, why can’t my servlet getthe parameters from the first code chunk? What’s wrong with setParams? Why can the servlet see parameters if I make them an entity?

  • 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-27T08:13:45+00:00Added an answer on May 27, 2026 at 8:13 am

    In HTML when we have something like “http://host/path?user=uname&passwd=pass”, we call the part (user=uname&passwd=pass) after the question mark “form data”.The “form data” can be attached to the end of the URL after a question mark (as above), for GET requests, or sent to the server on a separate line, for POST requests.The “form data” are split to parameters. The parameters are separated by & when we use GET.

    In our case the HttpPost and HttpGet classes extend the AbstractHttpMessage which implements the setParams method. This method is same for GET and POST but does the job only for GET! In the case of GET the parameters are put in the URL. In the case of POST you need to set the entity for the parameters to be on a “separate line”.

    On the server side when using servlets the getParameters is clever enough to find the parameters for GET and POST.

    Thats why on the server side we do not need to change the code for getting the parameters!

    Hope I helped!

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

Sidebar

Related Questions

This is just an out of curiosity question. Let's say you have a database
This is just a curiosity - I don't have a real question. The output
This is just a question out of curiosity since I have been needing to
This is more of a curiosity question than anything else. I'm new with Python
This is something now more of curiosity than actual purpose. If you have a
This is just a curiosity question I was wondering if anyone had a good
Its just a question out of curiosity. Suppose we have an associative array A.
Sorry for this curiosity that I have. sha1 use [a-f0-9] chars for its hashing
Just out of curiosity, how does iostream access the input-output system. (I have a
I have just inherited a server application, however it seems that the only copy

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.