2

I'm try to send some information in my android app using I tried this code

try{

    JSONObject j = new JSONObject();
    j.put("engineer", "me");

    httppost.setEntity(new UrlEncodedFormEntity(j));    
    HttpResponse response = httpclient.execute(httppost);

    /*Checking response*/
    if(response!=null)
    {   
        responseBody = EntityUtils.toString(response.getEntity());

    }
    if(responseBody.equals("ok"))
    {

        //...do something

    }
} catch(ClientProtocolException e) {

} catch (IOException e) {
    // TODO Auto-generated catch block
} catch(Exception e){
    e.printStackTrace();
}

but i think there is some error in

 httppost.setEntity(new UrlEncodedFormEntity(j));

can you please help me to solve this problem

1 Answer 1

0

You are putting the JSON instead of a name value pair. The JSON should be the value for another key or you do not use JSON for just a value and a key:

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("json", j.toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Sign up to request clarification or add additional context in comments.

3 Comments

it says json object type need to change string type What's wrong?
sorry, I edited my answer. Your JSON-Object needs to be converted to a string to be passed by POST.
Thank you friend .Can you please help me to solve this problem stackoverflow.com/questions/17896232/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.