1

I use HTTP-POST method for send the data to server with data and image also. I verify all the code. I did not get the error. My problem is when I am sending data, I got the json with

03-31 10:38:48.484: I/HTTP(28448): HTTP: OK
03-31 10:38:48.484: I/HTTP(28448): org.apache.http.conn.BasicManagedEntity@41ab71e0
03-31 10:38:48.485: I/Http Response:(28448): org.apache.http.message.BasicHttpResponse@41ab8cc8
03-31 10:38:48.489: I/MY RESPONSE(28448): {
03-31 10:38:48.489: I/MY RESPONSE(28448):   "status":0,
03-31 10:38:48.489: I/MY RESPONSE(28448):   "message":"please enter amount"
03-31 10:38:48.489: I/MY RESPONSE(28448): }

I PASS THE DATA IN AMOUNT BUT OUTPUT IS LIKE "PLEASE ENTER AMOUNT"

Please help me to solve the problem.

public void postData() {

        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, bao);
        byte[] ba = bao.toByteArray();
        String ba1 = Base64.encodeToString(ba, Base64.DEFAULT);

        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(
                "MY URL");

        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(7);
            //nameValuePairs.add(new BasicNameValuePair("amount", et_ans
                    //.getText().toString()));
                    nameValuePairs.add(new BasicNameValuePair("amount","12.12"));
            nameValuePairs.add(new BasicNameValuePair("shop",
                    autoCompleteTextView1.getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("date", txt_date
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("address", edt_address
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("state", txt_province
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("city", txt_city
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("image", ba1));

            Log.i("AMOUNT IS=", nameValuePairs.get(0).toString());
            Log.i("SHOP IS=", nameValuePairs.get(1).toString());
            Log.i("DATE IS=", nameValuePairs.get(2).toString());
            Log.i("ADDRESS IS=", nameValuePairs.get(3).toString());
            Log.i("STATE IS=", nameValuePairs.get(4).toString());
            Log.i("CITY IS=", nameValuePairs.get(5).toString());
            Log.i("IMAGE IS=", nameValuePairs.get(6).toString());

            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,
                    HTTP.UTF_8));

            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
            Log.i("HTTP", "HTTP: OK");
            Log.i("HTTP", response.getEntity().toString());

             Log.i("Http Response:", response.toString());



            try{
        bufferedReader = new BufferedReader(
                   new InputStreamReader(response.getEntity().getContent()));

        StringBuffer stringBuffer = new StringBuffer("");
        String line = "";
        String LineSeparator = System.getProperty("line.separator");
        while ((line = bufferedReader.readLine()) != null) {
            stringBuffer.append(line + LineSeparator); 
           }
           bufferedReader.close();

          // result.setText(stringBuffer.toString());

           Log.i("MY RESPONSE",stringBuffer.toString());
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally{
               if (bufferedReader != null){
                try {
                 bufferedReader.close();
                } catch (IOException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
                }
               }
              }
  • http://stackoverflow.com/questions/9397076/android-sending-an-image-through-post or http://stackoverflow.com/questions/9397076/android-sending-an-image-through-post for upload/post data and image on server – Narendra Mar 29 '14 at 12:05
  • postParameters.add( new BasicNameValuePair("double", Double.toString(123))); postParameters.add( new BasicNameValuePair("float", Float.toString(123.04))); – Dara Saini Mar 31 '14 at 05:23
  • @BKSINGH : nameValuePairs.add(new BasicNameValuePair("amount", et_ans.getText().toString())); I PASS THIS BUT GETTING THE SAME ERROR –  Mar 31 '14 at 05:29
  • @varshaBhatia Can you check serverside whats response you are getting when you call this webservice.? [Upload Image Sample with Data](http://stackoverflow.com/q/20297225/1160282) – SilentKiller Mar 31 '14 at 05:59
  • @SilentKiller : yes through iphone it sends the data and get the response but in android i don't get the response. –  Mar 31 '14 at 06:44
  • then check how data send in iPhone. – SilentKiller Mar 31 '14 at 06:46
  • @SilentKiller : means which things should i check how data send in iphone? –  Mar 31 '14 at 07:13

0 Answers0