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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:48:36+00:00 2026-06-15T01:48:36+00:00

I am creating httpClient and when I send httpPost method, how can I attach

  • 0

I am creating httpClient and when I send httpPost method, how can I attach a body to the httpRequest ??

 public String httpPost(String URL, String BODY) {

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(URL);



    try {

        response = httpclient.execute(httpPost); // get response from executing client

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            body.append(statusLine + "\n");
            HttpEntity e = response.getEntity();
            String entity = EntityUtils.toString(e);
            body.append(entity);

        } else {
            body.append(statusLine + "\n");
            // System.out.println(statusLine);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        httpPost.releaseConnection();
    }
    return body.toString();
}

For example, the string is
” < html > < header > Header < /header> < body> I am body < /body> “
Where do I attach that string to the request message ?
Thank you 🙂

  • 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-06-15T01:48:38+00:00Added an answer on June 15, 2026 at 1:48 am

    You can create a StringEntity, set it to the HttpPost object, and set the correct Content-Type:

    StringEntity entity = new StringEntity("data=" + java.net.URLEncoder.encode(body, "utf-8"));
    entity.setContentType("application/x-www-form-urlencoded");
    httpPost.setEntity(entity);
    

    And then send your POST request as usual.

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

Sidebar

Related Questions

I will try to give as much detail as I can. I am creating
I am sending a xml string to my web application using httpClient#execute(HttpPost, ResponseHandler) It
Creating a class at runtime is done as follows: klass = Class.new superclass, &block
everyone. I'm new here and this is my first post. I'm creating a simple
I have been using HTTPClient version 4.1.2 to try to access a REST over
I'm creating a unit test to try out the servlet I just created. @Test
using (var client = new System.Net.Http.HttpClient()) { var response = client.GetAsync(fullUrl).Result; } I am
What is the correct method to get the content of an URL in multiple
I am creating a server built in Visual Basic 2010 and that program can
I can find loads of tutorials that show how should a HttpClient constructed 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.