Search code examples
androidjsonhttprequestwp-api

how to send HttpRequest and get Json response in android?


i want to build an android app for my wordpress website using wp-api plugin. how can i send HttpRequest(GET) and recive response in Json?


Solution

  • Try below code to get json from a URL

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget= new HttpGet(URL);
    
    HttpResponse response = httpclient.execute(httpget);
    
    if(response.getStatusLine().getStatusCode()==200){
       String server_response = EntityUtils.toString(response.getEntity());
       Log.i("Server response", server_response );
    } else {
       Log.i("Server response", "Failed to get server response" );
    }