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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:50:29+00:00 2026-06-13T23:50:29+00:00

I want to construct a httprequest like below to access the rest webservice using

  • 0

I want to construct a httprequest like below to access the rest webservice using post request. I have used spring for android API to generate the request. I am able to add header with httpHeader.add method but dont know add message to the body. The request format is as below.

<?xml version="1.0" encoding="UTF-8"?>
<root>
<headers>
<messagetype>1</messagetype>
<uniquekey>95C75718-C774-DF4E-0DB4-A7AEF55077AA</uniquekey>
</headers>
<authentication>
<clientname>xxx</clientname>
<servicename>login</servicename>
<username>xxx123</username>
<password>welcome123</password>
</authentication>
</root>

I dont how to add that part. Please Help.

The code i done so far is below

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import org.springframework.web.client.RestTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;


public class Main extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TextView webservice = (TextView) findViewById(R.id.Webservice);

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.TEXT_PLAIN);
        requestHeaders.add("messagetype", "1");
        requestHeaders.add("uniquekey", UniqueID.getUUID());
        HttpEntity<String> requestEntity = new HttpEntity<String>(requestHeaders);
        RestTemplate restTemplate = new RestTemplate();
        String url = "http://www.localhost:8080/restwebservice/login";
        ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
        String result = responseEntity.getBody();       

        webservice.setText(result);
    }   
}
  • 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-13T23:50:30+00:00Added an answer on June 13, 2026 at 11:50 pm

    You need to create a Message object and pass it to the RestTemplate. Check out section 2.6.5 of the RestTemplate documentation for specifics.

    Note that the example there is different from your approach and uses postForObject instead of exchange. If you still want to stay with exchange, you should change the HttpEntity you are using for requestEntity and use one that allows you to add the body of your message to it. BasicHttpEntity should work just fine, although you will have to construct the XML in the body by hand. On the other hand, postForObject with the proper message formater will allow you to pass plain old Java object and get it properly serialized into XML automatically. There are many options for message formatters, but I would recommend Jackson as it is quite fast and well supported (even though it more known for its JSON support and less for XML).

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

Sidebar

Related Questions

i want to realize a construct in MS SQL that would look like this
I want to construct a SELECT statement with a conditional IF. Like, IF there
I have 2 WCF services now and I want to construct the WCF Service
I have a time series in R. I want to construct a matrix, where
I'd like to try to construct main.xml like in this application. Actually, I want
I want to construct where conditions based on setup data. But seems like where
I want to construct a std::string object like an array: std::string str(); str[0] =
I want to construct a query like this: SELECT * FROM t1 WHERE visible='yes'
Suppose I want to construct something like Array[#1^#2 == 3 &, {3, 3}] And
I want to construct a timeline that has horizontal scrolling. I have a wrapper

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.