title: Android Web Services Client (JSON)
body: <p>I am working on an android app, This app is a client for a web service running in glassfish 3.1.2.2, this web services work with xml and json parser's, i test externally de WS to view the answer what I get and when I looked for a xml answer from the server i get the xml data, and same happened with Json answer. </p>
  
  <p><strong>Problem</strong></p>
  
  <p>Problem come with the android client in the get method in which I set the content-type as application/json, but WS only response xml.</p>
  
  <p>Could anyone tell me where i am doing wrong, i will put the code and log in the end.</p>
  
  <p><strong>Code:-</strong></p>
  
  <pre><code>private class TareaWSObtener extends AsyncTask&lt;String, Integer, Boolean&gt;{
  
          //CONSTANTES
          private static final String CONTENT = "Content-Type"; //content-type
          private static final String JSONTYPE = "application/json"; //application/json
          private static final String LOGWS = "MovilSecure:WebServices";
          private int id;
          private String nombre;
  
          @Override
          protected Boolean doInBackground(String... params) {
              // TODO Auto-generated method stub
              boolean result = true;
  
              Log.i(LOGWS, "Levantando cliente");
              HttpClient httpClient = new DefaultHttpClient();
              HttpGet get = new HttpGet("http://10.0.2.2:8080/WS-MovilSecure_SandBox_ONLY_/webresources/persona");
              //get.setHeader("Content-Type", "application/json");
              Log.i(LOGWS, "cliente levantado");
              try{
                  Log.i(LOGWS, "Obteniendo data");
                  HttpResponse resp = httpClient.execute(get);
  
                  String stringRsp = EntityUtils.toString(resp.getEntity());
                  JSONObject respJSON = new JSONObject(stringRsp);
  
                  id = respJSON.getInt("idPersona");
                  nombre = respJSON.getString("nombre");
                  Log.i(LOGWS, "Data Obtenida");
  
              }
              catch(Exception e){
                  Log.e(LOGWS, "Problemas al conectar con el WS", e);
                  result = false;
              }
  
              return result;
          }
  
          protected void onPostExecute(boolean result){
              if(result){Log.i(LOGWS, "data:"+id+nombre);}
          }
  
      }
  </code></pre>
  
  <p><strong>Log:-</strong></p>
  
  <pre><code>09-13 21:52:50.073: I/MovilSecure:WebServices(3155): Levantando cliente
  09-13 21:52:50.123: I/MovilSecure:WebServices(3155): cliente levantado
  09-13 21:52:50.123: I/MovilSecure:WebServices(3155): Obteniendo data
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155): Problemas al conectar con el WS
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155): org.json.JSONException: Value &lt;?xml       of type java.lang.String cannot be converted to JSONObject
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at org.json.JSON.typeMismatch(JSON.java:111)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at org.json.JSONObject.&lt;init&gt;(JSONObject.java:158)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at org.json.JSONObject.&lt;init&gt;(JSONObject.java:171)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at com.example.wsclient_movilesecure.MainActivity$TareaWSObtener.doInBackground(MainActivity.java:110)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at com.example.wsclient_movilesecure.MainActivity$TareaWSObtener.doInBackground(MainActivity.java:1)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
  09-13 21:52:50.293: E/MovilSecure:WebServices(3155):    at java.lang.Thread.run(Thread.java:841)
  </code></pre>