Example usage for org.apache.http.client.methods HttpGet HttpGet

List of usage examples for org.apache.http.client.methods HttpGet HttpGet

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpGet HttpGet.

Prototype

public HttpGet(final String uri) 

Source Link

Usage

From source file:com.iiordanov.wiktionarylookup.util.HttpUtil.java

public static String curl(String url) {
    String html = null;// ww  w . ja v a 2  s  .c  o m

    try {
        HttpUriRequest get = new HttpGet(url);
        HttpResponse response = new DefaultHttpClient().execute(get);
        html = EntityUtils.toString(response.getEntity(), "utf-8");
    } catch (ClientProtocolException e) {
        //Log.e (Global.TAG, "Could not curl", e);
    } catch (IOException e) {
        //Log.e (Global.TAG, "Could not curl", e);
    }

    return html;
}

From source file:org.opencastproject.remotetest.server.resource.StateResources.java

public static HttpResponse recordings(TrustedHttpClient client) throws Exception {
    return client.execute(new HttpGet(getServiceUrl() + "recordings"));
}

From source file:org.xmlvm.demo.java.photovm.net.HTTPRequest.java

public static String get(String url) {
    HttpGet method = new HttpGet(url);
    try {//from   w w w.  jav a  2s.c  o m
        HttpResponse response = client.execute(method);
        int returnCode = response.getStatusLine().getStatusCode();
        if ((returnCode >= 200) && (returnCode < 300)) {
            StringBuilder st = new StringBuilder();
            BufferedReader r = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            while (r.ready()) {
                st.append(r.readLine() + "\n");
            }
            return st.toString();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:de.rallye.test.helper.HttpClient.java

public static HttpResponse apiCall(String url, int expectedStatusCode) throws IOException {
    HttpGet httpget = new HttpGet("http://localhost:10111/" + url);
    HttpResponse r = httpclient.execute(httpget);
    int statusCode = r.getStatusLine().getStatusCode();
    if (expectedStatusCode != statusCode) {
        System.err.println("Got unexpected status code: " + statusCode);
        // Let's see if it's printable
        boolean printable = true;
        Header[] ct = r.getHeaders("Content-Type");
        if (ct.length > 0) {
            String type = ct[0].getValue();
            printable = (type.startsWith("text/") || type.startsWith("application/"));
        }// w w  w  . java2s.com

        if (printable) {
            System.err.println("This is the content:");
            List<String> contents = IOUtils.readLines(r.getEntity().getContent());
            for (String line : contents)
                System.err.println(line);
        }

        assertEquals("StatusCode should match expected", expectedStatusCode, statusCode);

    }
    return r;
}

From source file:language_engine.HttpUtils.java

public static String doHttpGet(String url) {
    try {//  w  w w .j a  v a2s .  c  om
        HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(url);
        HttpResponse resp = httpClient.execute(httpGet);

        return StreamUtil.readText(resp.getEntity().getContent(), "UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.fcrepo.camel.indexing.solr.integration.TestUtils.java

public static InputStream httpGet(final String url) throws Exception {
    final CloseableHttpClient httpClient = HttpClients.createDefault();
    final HttpGet get = new HttpGet(url);
    return httpClient.execute(get).getEntity().getContent();
}

From source file:com.earth.places.utilities.JSONParser.java

public static JSONObject getJSONFromURL(String url) {

    try {//from  www  .j av a  2 s. c om

        HttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute(new HttpGet(url));

        if (response.getStatusLine().getStatusCode() == 200) {

            final String data = EntityUtils.toString(response.getEntity());
            return new JSONObject(data);

        }

    } catch (Exception e) {
        Log.d(TAG, "No response from the server, where you have stored your json: " + e.getMessage());
    }

    return null;
}

From source file:org.opencastproject.remotetest.server.resource.CaptureAdminResources.java

public static HttpResponse recordings(TrustedHttpClient client) {
    return client.execute(new HttpGet(getServiceUrl() + "recordings"));
}

From source file:org.opencastproject.remotetest.server.resource.ComposerResources.java

public static HttpResponse profiles(TrustedHttpClient client) {
    return client.execute(new HttpGet(getServiceUrl() + "profiles"));
}

From source file:net.locosoft.fold.neo4j.internal.Neo4jRestUtil.java

public static JsonObject doGetJson(String uri) {
    try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
        CloseableHttpResponse response = httpClient.execute(new HttpGet(uri));

        String bodyText = EntityUtils.toString(response.getEntity());
        JsonObject jsonObject = JsonObject.readFrom(bodyText);
        return jsonObject;
    } catch (Exception ex) {
        ex.printStackTrace();/*from  ww  w .  j  a v a 2 s  .  c o  m*/
    }
    return null;
}