Postman is working, cannot send raw data on Android

I was trying to send like : Here’s the raw data that I am using in postman’s that is working however, I don’t know what is the problem

{“userid”: “ssrci”,”pass”:”1222″}

I am guessing it was sending a plain text instead of json formatted text. I am not getting the result I want to receive once I send the data

Here’s my code

    protected void onCreate(Bundle savedInstanceState) {

        // get reference to the views
        userId = (EditText) findViewById(;
        password = (EditText) findViewById(;
        btnPost = (Button) findViewById(;

        // add click listener to Button "POST"


    public static String POST(String url, Account account) {
        InputStream inputStream = null;
        String result = "";
        try {

            // 1. create HttpClient
            HttpClient httpclient = new DefaultHttpClient();

            // 2. make POST request to the given URL
            HttpPost httpPost = new HttpPost(url);

            String json = "";

            // 3. build jsonObject
            JSONObject jsonObject = new JSONObject();
            jsonObject.accumulate("userid", account.getUserid());
            jsonObject.accumulate("password", account.getPassword());

            // 4. convert JSONObject to JSON to String
            json = jsonObject.toString();

            // 5. set json to StringEntity
            StringEntity se = new StringEntity(json);

            // 6. set httpPost Entity

            // 7. Set some headers to inform server about the type of the content
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json");

            // 8. Execute POST request to the given URL
            HttpResponse httpResponse = httpclient.execute(httpPost);

            // 9. receive response as inputStream
            inputStream = httpResponse.getEntity().getContent();

            // 10. convert inputstream to string
            if (inputStream != null)
                result = convertInputStreamToString(inputStream);
                result = "Did not work!";

        } catch (Exception e) {
            Log.d("InputStream", e.getLocalizedMessage());

        // 11. return result
        return result;

    public void onClick(View view) {

        switch (view.getId()) {
                if (!validate())
                    Toast.makeText(getBaseContext(), "Enter some data!", Toast.LENGTH_LONG).show();
                // call AsynTask to perform network operation on separate thread
                new HttpAsyncTask().execute("");


private class HttpAsyncTask extends AsyncTask<String, Void, String> {
            protected String doInBackground(String... urls) {
                account = new Account();

                return POST(urls[0], account);

            // onPostExecute displays the results of the AsyncTask.
            protected void onPostExecute(String result) {
                Toast.makeText(getBaseContext(), "Data Sent!" + result, Toast.LENGTH_LONG).show();


Here’s the account

class Account {

    private String userid;
    private String password;

    public String getUserid() {
        return userid;

    public void setUserid(String userid) {
        this.userid = userid;

    public String getPassword() {
        return password;

    public void setPassword(String password) {
        this.password = password;

    public String toString() {
        return "[userid=" + userid + ", pass=" + password + "]";

There’s something I missed that needs reconfiguration??
Could you please help me with some code solution ? Thanks

You are missing the ContentType when creating your StringEntity (so it is defaulting to TEXT_PLAIN, but you probably want to use APPLICATION_JSON)

In your code, change:

StringEntity se = new StringEntity(json);


StringEntity se = new StringEntity(json, ContentType.APPLICATION_JSON);

username and password is case sensitive, just set this

 JSONObject jsonObject = new JSONObject();
                jsonObject.accumulate("userid", account.getUserid());
                jsonObject.accumulate("pass", account.getPassword());


{“userid”: “ssrci”,”pass”:”1222″}

and use above code.