Example usage for org.apache.http.entity StringEntity toString

List of usage examples for org.apache.http.entity StringEntity toString

Introduction

In this page you can find the example usage for org.apache.http.entity StringEntity toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:manager.computerVisionManager.java

private static void getJson(String path) {
    System.out.println("Get Description from https://westus.api.cognitive.microsoft.com/vision/v1.0/describe");
    try {/*from   www.j  a  v a 2  s.  c om*/
        URIBuilder builder = new URIBuilder("https://westus.api.cognitive.microsoft.com/vision/v1.0/describe");
        builder.setParameter("maxCandidates", "1");
        URI uri = builder.build();
        HttpPost request = new HttpPost(uri);
        request.setHeader("Content-Type", "application/json");
        request.setHeader("Ocp-Apim-Subscription-Key", "d7f6ef12e41c4f8c8e72d12a890fa703");
        // Request body
        StringEntity reqEntity = new StringEntity("{\"url\":\"" + path + "\"}");
        System.out.println("Request String: " + reqEntity.toString());
        request.setEntity(reqEntity);
        HttpResponse response = httpclient.execute(request);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            String respuesta = EntityUtils.toString(entity);
            JSONParser lector = new JSONParser();
            StringReader SR = new StringReader(respuesta);
            try {
                JSONObject temp = (JSONObject) lector.parse(SR);
                json = (JSONObject) temp.get("description");
            } catch (org.json.simple.parser.ParseException e) {
                System.err.println(e.getMessage());
            }
        }
    } catch (IOException | URISyntaxException | ParseException e) {
        System.err.println(e.getMessage());
    }
}

From source file:com.example.administrator.myapplication2._3_HB._3_MainActivity.java

public void HttpPostDateTest(StringEntity entity) {
    Log.i("boogil", "httpPost ?1: " + entity.toString());

    StringEntity entity1 = entity;//ww  w  .jav a 2s.  c  o m

    AsyncHttpClient client = new AsyncHttpClient();

    client.post(this.getApplicationContext(), "http://14.63.219.140:8080/fstepApp/webresources/fsteppack.test",
            entity1, "application/json", new JsonHttpResponseHandler() {
                //client.post(this.getApplicationContext(),"http://14.63.219.140:8080/fstepApp/webresources/fsteppack.member1",entity1,  "application/json",new JsonHttpResponseHandler() {
                @Override
                public void onStart() {
                    // called before request is started
                    // TODO Auto-generated method stub
                    Log.i("boogil", "onStart! ");

                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    Log.i("boogil", "success!! ");

                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                    Log.i("boogil", "success!! ");
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, String responseString,
                        Throwable throwable) {
                    Log.i("boogil", "fail3!! ");

                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, String responseString) {
                    Log.i("boogil", "success!! ");
                }

            });

    AsyncHttpClient client1 = new AsyncHttpClient();
    client1.get("http://14.63.219.140:8080/fstepApp/webresources/fsteppack.test/alarm/0",
            new JsonHttpResponseHandler() {

                @Override
                public void onStart() {
                    // called before request is started
                    // TODO Auto-generated method stub
                    Log.i("boogil1", "onStart! ");

                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                    Log.i("boogil1", "success!! ");
                    Log.i("boogil1", response.toString());
                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
                    Log.i("boogil1", "success!! ");
                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, String responseString) {
                    Log.i("boogil1", "success!! ");
                }

                @Override
                public void onFailure(int statusCode, Header[] headers, String responseString,
                        Throwable throwable) {
                    Log.i("boogil1", "fail3!! ");

                }
            });

}