1

I'm trying to get data from server by setting parameters in Http post method (like mentioned here)

It works great when params are directly set in url, but when i try to set parameters using setEntity(new UrlEncodedFormEntity(nameValuePairs)) server returns blank answer (like i haven't defined any variable). Here is my doInBackground() code :

     String inMsg = "";
        String url = "xxx";

         HttpClient client = new DefaultHttpClient();
         DataOutputStream dataOutputStream = null;
         BufferedReader input = null;
         HttpPost post = new HttpPost(url);

         List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
         nameValuePairs.add(new BasicNameValuePair("retrieve", "test"));
         try {

             post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
             HttpResponse response = client.execute(post);
             HttpEntity entity = response.getEntity();

          if (isCancelled())
             {
              publishProgress(CANCELLED);
              return (null);
             }

          input = new BufferedReader( new InputStreamReader (entity.getContent(), "iso-8859-1"), 8);

          StringBuilder inptemp = new StringBuilder();
          while ((inMsg = input.readLine()) != null)
          {
              inptemp.append(inMsg + "\n"); 
          }

          publishProgress(SUCCESS);

          if (isCancelled())
             {
              publishProgress(CANCELLED);
              return (null);
             }

          inMsg = "";
          inMsg = inptemp.toString();


          Log.w("params", "msg: "+inMsg);
          Log.w("params", url);
          JSONArray jArray = new JSONArray(inMsg);
            for(int i=0;i<jArray.length();i++){
                    JSONObject json_data = jArray.getJSONObject(i);
                    Log.w("log_tag","id: "+json_data.getInt("Id")

                    );

                    //Get an output to the screen
                    //return String += "\n\t" + jArray.getJSONObject(i); 
            }

Any suggestions ?

Community
  • 1
  • 1
user2445034
  • 41
  • 1
  • 7

0 Answers0