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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:34+00:00 2026-05-24T21:35:34+00:00

i have the following code in my client: Log.v(TAG, Trying to Login); HttpClient client

  • 0

i have the following code in my client:

    Log.v(TAG, "Trying to Login");
    HttpClient client = new DefaultHttpClient();
    EditText etxt_user = (EditText) findViewById(R.id.username);
    EditText etxt_pass = (EditText) findViewById(R.id.password);
    String username1 = etxt_user.getText().toString();
    String password1 = etxt_pass.getText().toString();
    HttpPost httppost = new HttpPost("http://10.0.2.2:8888");
    Log.v(TAG, "message1");         
    //add your Data
    List< BasicNameValuePair > nvps = new ArrayList< BasicNameValuePair >();
    nvps.add(new BasicNameValuePair("username", username1));
    nvps.add(new BasicNameValuePair("password", password1));

    try {
          UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);
          httppost.setEntity(p_entity);
          //Execute HTTP Post Request
          HttpResponse response = client.execute(httppost);

          Log.v(TAG,"message2");
          Log.v(TAG, response.getStatusLine().toString());
          HttpEntity responseEntity = response.getEntity();

And my web service has the following code:

public Source invoke(Source request){
        String replyElement = new String("hello world");
        StreamSource reply = new StreamSource(new StringReader(replyElement));
        String replyElement2 = new String("hello world 2");
        StreamSource reply2 =  new StreamSource(new StringReader(replyElement2));
        String amount = null;
        if (ws_ctx == null)throw new RuntimeException("DI failed on ws_ctx.");
        if (request == null) {
            System.out.println("Getting input from query string");
            // Grab the message context and extract the request verb.
            MessageContext msg_ctx = ws_ctx.getMessageContext();
            String x = msg_ctx.toString();
            System.out.println("The value" + x + "was received from the client");
            String http_verb = (String)msg_ctx.get(MessageContext.HTTP_REQUEST_METHOD);
            System.out.println(http_verb);
            String query = (String)msg_ctx.get(MessageContext.QUERY_STRING);
            System.out.println("Query String = " + query);   
            if(query == null)
            {
                System.out.println("The query variable has zero value!!!!!");
            }
            else
            {
                System.out.println("The value of the query variable is:" + query);
            }

            http_verb = http_verb.trim().toUpperCase()

        } else {
            System.out.println("Getting input from input message");
            Node n = null;
            if (request instanceof DOMSource) {
                n = ((DOMSource) request).getNode();
            } else if (request instanceof StreamSource) {
                StreamSource streamSource = (StreamSource) request;
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                DocumentBuilder db = dbf.newDocumentBuilder();
                InputSource inputSource = null;
                if (streamSource.getInputStream() != null) {
                    inputSource = new InputSource(streamSource.getInputStream());
                } else if (streamSource.getReader() != null) {
                    inputSource = new InputSource(streamSource.getReader());
                }
                n = db.parse(inputSource);
            } else {
                throw new RuntimeException("Unsupported source: " + request);
            }

        }

    return reply2;
    }
    catch(Exception e){
        e.printStackTrace();
        throw new HTTPException(500);
    }

}

}

The client communicates with the server, but the server reads the parameters username and password only when i put the parameters in the URL like this:

HttpPost httppost = new HttpPost("http://10.0.2.2:8888"+"?username=" + username1 + "&password=" + password1);

How can the server read the parameters from the entity body? I am trying to send the parameters from the client using this line:

UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8);

Isn’t it better to pass the parameters in the entity body?

  • 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-24T21:35:35+00:00Added an answer on May 24, 2026 at 9:35 pm

    You could try the following and see if it works (I’ve used it before)

    
        StringEntity params = new StringEntity("username=" + username1 + "&password=" + password1);         
        HttpPost request = new HttpPost(path);
        HttpClient httpClient = new DefaultHttpClient();
        request.addHeader("content-type", "application/x-www-form-urlencoded");
        request.setEntity(params);
    
    

    Hope it works for you as well.

    And if you are working on very simple Server side (as your question suggested) you might want to look at other framework that I mentioned below. Primarily look at this code example for JAX-RS:

    
    
        @POST
            @Produces(MediaType.TEXT_HTML)
            @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
            public void newTodo(
                    @FormParam("id") String id,
                    @FormParam("summary") String summary,
                    @FormParam("description") String description,
                    @Context HttpServletResponse servletResponse
            ) throws IOException {
                Todo todo = new Todo(id,summary);
                if (description!=null){
                    todo.setDescription(description);
                }
                TodoDao.instance.getModel().put(id, todo);
    
                URI uri = uriInfo.getAbsolutePathBuilder().path(id).build();
                Response.created(uri).build();
    
                servletResponse.sendRedirect("../create_todo.html");
            }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario. The client code only has access to FooHandler, not
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following client code: |>! OnClick (fun _ _ -> Server.CreateBug input.Value
I have the following code in an HTML file: socket.on('message',function(data) { console.log('Received a message
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
i have following code to show div on page <div id=all_users> <div id=user11 userid=11

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.