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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:01:00+00:00 2026-05-23T12:01:00+00:00

I need to work with REST api in android application which is created by

  • 0

I need to work with REST api in android application which is created by my client. Below text is just copied from the pdf the client provides us.

—
In this example, a new user is created.
The parts of a possible request to the server is shown below:

Message part Contents

Header POST {url-prefix}/rest/user
Content-Type: application/xml
Content-Length: 205
Body <request>
  <client>
    <id>XY</id>
    <name>myName</name>
    <password>myPassword</password>
  </client>
  <user>
    <name>myUserName</name>
    <password>myUserPassword</password>
    <groupId>12345</groupId>
  </user>
</request>

—
After searching and studying, I come to know that, the possible request code (in Java) might be:

URL url=new URL("http://api.example.com/rest/user/?name=myUserName&password=myUserPassword&groupId=12345");
            HttpURLConnection conn=(HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("Post");
            OutputStreamWriter out=new OutputStreamWriter(conn.getOutputStream());
            out.write("respose content:");
            out.close();

From the pdf manual they provide, I got to know, for every request to the server, the client (thats me) has to transmit the authentication data.
My question is, where do I put the authentication data in the query string? Please help me on this.

Edit:After posting the below code as request:

            DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://api.example.com/rest/user/?name=Foysal&password=123456&groupid=12345");
            httpPost.addHeader("Accept", "text/xml");
            httpPost.setHeader("Content-Type","application/xml;charset=UTF-8");
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("name", "APIappDevAccount"));
            nameValuePairs.add(new BasicNameValuePair("password", "123456"));           
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpParams params = new BasicHttpParams();
            HttpConnectionParams.setStaleCheckingEnabled(params, false);
            HttpConnectionParams.setConnectionTimeout(params, 5000);
            HttpConnectionParams.setSoTimeout(params, 5000);
            httpClient.setParams(params);
            httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);
            HttpResponse response = httpClient.execute(httpPost);
            InputStream is = response.getEntity().getContent();
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            byte[] buf;
            int ByteRead;
            buf = new byte[1024];
            String xmldata = null;
            double totalSize = 0;
            while ((ByteRead = is.read(buf, 0, buf.length)) != -1) {
                os.write(buf, 0, ByteRead);
                totalSize += ByteRead;                      
            }
            xmldata =  os.toString();
            os.close();
            is.close();

But I got the response as:

404
Not Found

Not Found

The requested
URL /rest/user/ was not found on this
server.


Apache/2.2.6
(Fedora) DAV/2 mod_ssl/2.2.6
OpenSSL/0.9.8b Server at
api.example.com Port 80

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

    Looks to me like they want you to POST an XML document and put the authentication in that. Not much of a REST API (most REST APIS don’t require an XML document).

    You need to use conn.getOutputStream() to send that doc to the server and use conn.getInputStream() to read the response.

    So you would have to create the XML doc like the one they show:

    <request>
      <client>
        <id>XY</id>
        <name>myName</name>
        <password>myPassword</password>
      </client>
      <user>
        <name>myUserName</name>
        <password>myUserPassword</password>
        <groupId>12345</groupId>
      </user>
    </request>
    

    And then send it in your POST:

    conn.setRequestProperty ( "Content-Type", "text/xml" );
    out.write(requestDoc); //where requestDoc is the String containing the XML.
    out.flush();
    out.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to work with array from several threads, so I use CRITICAL SECTION
For my work I need to create a Autorun application for a CD for
I need my program to work only with certain USB Flash drives (from a
I am working on building an REST API in PHP, I need to know
I need to solve the following question which i can't get to work by
I need to work with MSMQ (Microsoft Message Queuing). What is it, what is
Every time I need to work with date and/or timstamps in Java I always
I am a Java programmer and need to work on a Flex/ActionScript project right
I have a situation where I need to work with a datagrid and adding
I need to do some work with a backup WSS .dat file and I'm

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.