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

The Archive Base Latest Questions

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

i am using following code to make an httpPost call but it is returning

  • 0

i am using following code to make an httpPost call but it is returning me 400 bad request
when i try to give following parameters in “simple rest client” in chrome extension it works fine any one guide me what mistake am i doing here?

Simple rest Client I entered the following:

URL: http://jon2012.com/api/register
Method: POST
Headers: No headers, as they are not required
Data: { “email”: “test@example.com”, “first_name”:”Name” }enter image description here

Android Code:

HttpClient client = new DefaultHttpClient();
        HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
        HttpResponse response;
        JSONObject json = new JSONObject();
        try{
            HttpPost post = new HttpPost(url);
            json.put("email", email);
            json.put("first_name", name);
            StringEntity se = new StringEntity( "JSON: " + json.toString());  
            se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
            post.setEntity(se);
            response = client.execute(post);
            /*Checking response */
            /*if(response!=null){
                InputStream in = response.getEntity().getContent(); //Get the data in the entity
*/
            int statusCode = response.getStatusLine().getStatusCode();

        }
        catch(Exception e){
            e.printStackTrace();
           // createDialog("Error", "Cannot Estabilish Connection");
        }

any help would be appriciated

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

    I was making a common mistake sequence of json object was wrong.
    For example, I was sending it like
    first_name, email, etc. where as the correct sequence was email, first_name.

    My code:

    boolean result = false;
    HttpClient hc = new DefaultHttpClient();
    String message;
    
    HttpPost p = new HttpPost(url);
    JSONObject object = new JSONObject();
    try {
        object.put("updates", updates);
        object.put("mobile", mobile);
        object.put("last_name", lastname);
        object.put("first_name", firstname);
        object.put("email", email);
    
    } catch (Exception ex) {
    
    }
    
    try {
        message = object.toString();
    
        p.setEntity(new StringEntity(message, "UTF8"));
        p.setHeader("Content-type", "application/json");
        HttpResponse resp = hc.execute(p);
        if (resp != null) {
            if (resp.getStatusLine().getStatusCode() == 204)
                result = true;
        }
    
        Log.d("Status line", "" + resp.getStatusLine().getStatusCode());
    } catch (Exception e) {
        e.printStackTrace();
    
    }
    
    return result;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using following code to make a phone call from my iPhone app:
I'm using the following code to make cross domain request using $.getJSON, request completed
Using the following code I get a nice formatted string: Request.QueryString.ToString Gives me something
I'm using the following code to query a database from my jsp, but I'd
I am currently using the following code to create a web request: Dim myRequest
I am using the following code to make a HttpWebRequest and render the XML
I'm using the following code to make my treenodes bold: Font font = new
I am using following code to make a screen shot UIGraphicsBeginImageContext(self.view.frame.size); blendMode:kCGBlendModeClear alpha:1.0]; [self.view.window.layer
I m having following screen, I am using Following code to make Layout to
I am using following code for notification. It should vibrate and make sound at

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.