Pegar en Runtime eclipse/GeneradoTest3/GeneradoTest3/ANDROID/Componente1_localizacion/Application/src/main/java/com/litierses/Utilidades/JSONParser.java
// by making HTTP POST or GET mehtod

by making HTTP POST or GET mehtod
by making HTTP POST or GET mehtod
public JSONArray makeHttpRequest(String url, String method,
                                      String params) {
        try {
            if(method == "POST"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setEntity(new StringEntity(params));
                httpPost.setHeader("Accept", "application/json");
                httpPost.setHeader("Content-type", "application/json");
                HttpResponse httpResponse = httpClient.execute(httpPost);
            }else if(method == "GET"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(url);
                httpGet.setHeader("Accept", "application/json");
                httpGet.setHeader("Content-type", "application/json");
                HttpResponse httpResponse = httpClient.execute(httpGet);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }
            else if(method == "DELETE"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpDelete httpDelete = new HttpDelete(url);
                httpDelete.setHeader("Accept", "application/json");
                httpDelete.setHeader("Content-type", "application/json");
                HttpResponse httpResponse = httpClient.execute(httpDelete);
                HttpEntity httpEntity = httpResponse.getEntity();
                is = httpEntity.getContent();
            }
            else if(method == "PUT"){
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPut httpPut = new HttpPut(url);
                httpPut.setEntity(new StringEntity(params));
                httpPut.setHeader("Accept", "application/json");
                httpPut.setHeader("Content-type", "application/json");
                HttpResponse httpResponse = httpClient.execute(httpPut);
            }
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (is != null)
        {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
        try {
            jObj = new JSONArray(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        }
        return jObj;
    }
public JSONArray makeHttpRequest ( String url , String method , String params ) { try { if ( method == "POST" ) { DefaultHttpClient httpClient = new DefaultHttpClient ( ) ; HttpPost httpPost = new HttpPost ( url ) ; httpPost . setEntity ( new StringEntity ( params ) ) ; httpPost . setHeader ( "Accept" , "application/json" ) ; httpPost . setHeader ( "Content-type" , "application/json" ) ; HttpResponse httpResponse = httpClient . execute ( httpPost ) ; } else if ( method == "GET" ) { DefaultHttpClient httpClient = new DefaultHttpClient ( ) ; HttpGet httpGet = new HttpGet ( url ) ; httpGet . setHeader ( "Accept" , "application/json" ) ; httpGet . setHeader ( "Content-type" , "application/json" ) ; HttpResponse httpResponse = httpClient . execute ( httpGet ) ; HttpEntity httpEntity = httpResponse . getEntity ( ) ; is = httpEntity . getContent ( ) ; } else if ( method == "DELETE" ) { DefaultHttpClient httpClient = new DefaultHttpClient ( ) ; HttpDelete httpDelete = new HttpDelete ( url ) ; httpDelete . setHeader ( "Accept" , "application/json" ) ; httpDelete . setHeader ( "Content-type" , "application/json" ) ; HttpResponse httpResponse = httpClient . execute ( httpDelete ) ; HttpEntity httpEntity = httpResponse . getEntity ( ) ; is = httpEntity . getContent ( ) ; } else if ( method == "PUT" ) { DefaultHttpClient httpClient = new DefaultHttpClient ( ) ; HttpPut httpPut = new HttpPut ( url ) ; httpPut . setEntity ( new StringEntity ( params ) ) ; httpPut . setHeader ( "Accept" , "application/json" ) ; httpPut . setHeader ( "Content-type" , "application/json" ) ; HttpResponse httpResponse = httpClient . execute ( httpPut ) ; } } catch ( UnsupportedEncodingException e ) { e . printStackTrace ( ) ; } catch ( ClientProtocolException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } if ( is != null ) { try { BufferedReader reader = new BufferedReader ( new InputStreamReader ( is , "iso-8859-1" ) , 8 ) ; StringBuilder sb = new StringBuilder ( ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { sb . append ( line + "\n" ) ; } is . close ( ) ; json = sb . toString ( ) ; } catch ( Exception e ) { Log . e ( "Buffer Error" , "Error converting result " + e . toString ( ) ) ; } try { jObj = new JSONArray ( json ) ; } catch ( JSONException e ) { Log . e ( "JSON Parser" , "Error parsing data " + e . toString ( ) ) ; } } return jObj ; }
by making HTTP POST or GET mehtod
by making HTTP POST or GET mehtod
// Making HTTP request
 // check for request method
 // request method is GET
 // try parse the string to a JSON object
 // return JSON String
