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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:34:26+00:00 2026-05-31T12:34:26+00:00

I want to hit a Post request in android with an Input xml and

  • 0

I want to hit a Post request in android with an Input xml and get output as xml. Please tell me the way to achieve this in android java. I have done this in iPhone objective-c.

Thanks in advance

  • 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-31T12:34:28+00:00Added an answer on May 31, 2026 at 12:34 pm

    Call Connection Manager Class:
    Send Request Using this Code: pass url and xml-req

                 String url=" Enter URL Here"
        ConnectionManager connectionManger = new ConnectionManager(url);
            connectionManger.AddParam("xml_req", xml_req);
            try {
                response = connectionManger.sendRequest(RequestMethod.POST);
            } catch (Exception e) {
                e.printStackTrace();
            }
    

    Connection Manager Class:

    import android.content.Context;
    
    import com.mutmonix.series.bo.RequestMethod;
    
    public class ConnectionManager {
         private  ArrayList <NameValuePair> params;
         private  ArrayList <NameValuePair> headers;
         private String url;
    
        public static Context context;
    
        File tempDir;
    
        public ConnectionManager(String url) {
            this.url = url;
            params = new ArrayList<NameValuePair>();
            headers = new ArrayList<NameValuePair>();
        }
    
        public String sendRequest(RequestMethod method)throws Exception {   
            return callServer(method);
        }
    
    
         public void AddParam(String name, String value)
            {
                params.add(new BasicNameValuePair(name, value));
            }
    
            public void AddHeader(String name, String value)
            {
                headers.add(new BasicNameValuePair(name, value));
            }
    
    
            public String callServer(RequestMethod method) throws Exception {
                String xmlResponse = "";
    
                switch(method) {
                case GET:
                {
                    //add parameters
                    String combinedParams = "";
                    if(!params.isEmpty()){
                        combinedParams += "?";
                        for(NameValuePair p : params)
                        {
                            String paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(),"UTF-8");
                            if(combinedParams.length() > 1)
                            {
                                combinedParams  +=  "&" + paramString;
                            }
                            else
                            {
                                combinedParams += paramString;
                            }
                        }
                    }
    
                    HttpGet request = new HttpGet(url + combinedParams);
    
                    //add headers
                    for(NameValuePair h : headers)
                    {
                        request.addHeader(h.getName(), h.getValue());
    
                    }
    
                    xmlResponse = executeRequest(request, url);
                    break;
                }
                case POST:
                {
                    HttpPost request = new HttpPost(url);
    
    
                    //add headers
                    for(NameValuePair h : headers)
                    {
                        StringEntity entity = new StringEntity(h.getValue(), "UTF-8");
                        request.setEntity(entity);  
                        request.addHeader("Accept", "application/xml");
                        request.addHeader("Content-Type", "application/xml");
    
    
                    }
    
                    if(!params.isEmpty()){
                        request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
                    }
    
                    xmlResponse = executeRequest(request, url);
                    break;
                }
                case PUT:
                {
                    HttpPut request = new HttpPut(url);
    
                    //add headers
                    for(NameValuePair h : headers)
                    {
                        StringEntity entity = new StringEntity(h.getValue(), "UTF-8");                  
                        request.setEntity(entity);  
                        request.addHeader("Accept", "application/xml");
                        request.addHeader("Content-Type", "application/xml");
    
    
                    }
    
                    if(!params.isEmpty()){
                        request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
                    }
    
                    xmlResponse = executeRequest(request, url);
                    break;
                }
    
            }
                return xmlResponse;
            }
    
    
    
               private String executeRequest(HttpUriRequest request, String url) throws Exception
               {
                   //HttpClient client = new DefaultHttpClient();
                   DefaultHttpClient client = new DefaultHttpClient();
                   HttpParams params = client.getParams();
    
                   // Set Connection TimeOut
                   HttpConnectionParams.setConnectionTimeout(params, 30000);
    
                   HttpResponse httpResponse;
                   String xmlResponse = "";         
                   httpResponse = client.execute(request);
                   int responseCode = httpResponse.getStatusLine().getStatusCode();
                   String message = httpResponse.getStatusLine().getReasonPhrase();
                   HttpEntity entity = httpResponse.getEntity();
                   if (entity != null) {
                       InputStream instream = entity.getContent();
                       xmlResponse = convertStreamToString(instream);
    
                       // Closing the input stream will trigger connection release
                       instream.close();
                   }
    
                   return xmlResponse;    
               }
    
        private String convertStreamToString(InputStream is) {
    
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            StringBuilder sb = new StringBuilder();
    
            String line = null;
            try {
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "\n");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return sb.toString();
        }
    }
    

    Request Type Class:

    public enum RequestMethod
    {
    GET,
    POST,
    PUT
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi im developing an android app using facebook sdk in this app i want
I want my user to be able to hit the submit button and have
i want to reduce the number of times i hit the data base to
I'm trying to figure out Elisp, and I've hit a roadblock. I want a
want to ask user to input something but not want to wait forever. There
I've scoured the internet for a while now and I cannot get my Android
I have an application App2 to which I am sending a POST request from
I am trying to build a webservice that manipulates http requests POST and GET.
I hit this problem in Windows Forms, after using PInvoke of SetWindowLongPtr to remove
Again, to re-iterate: This is not a request to program anything for me. I

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.