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.vmware.identity.rest.core.client.RequestFactory.java

public static HttpGet createGetRequest(URI uri) {
    return prepareRequest(new HttpGet(uri), null);
}

From source file:com.magi.web.WebParser.java

public String parse() throws IOException {
    System.out.println("URL: " + url);

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(url);
    HttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    if (entity != null) {
        int bread = 0;
        byte[] buff = new byte[512];
        StringBuffer sbuff = new StringBuffer();
        InputStream instream = entity.getContent();
        while ((bread = instream.read(buff)) != -1) {
            sbuff.append(new String(buff, 0, bread));
        }/* w  w w  .j  av  a 2s. c om*/
        // Do not need the rest
        httpget.abort();

        parseText(sbuff.toString());
        return sbuff.toString();
    }

    return null;
}

From source file:de.devbliss.apitester.factory.impl.DefaultGetFactory.java

public HttpGet createGetRequest(URI uri) throws IOException {
    return new HttpGet(uri);
}

From source file:conexao.Conexao.java

public PlayerGames getPlayerGames(Long summonerId) {
    PlayerGames example = null;//from  w  w w . j  ava  2s.co  m
    try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet getRequest = new HttpGet("https://br.api.pvp.net/api/lol/br/v1.3/game/by-summoner/" + summonerId
                + "/recent?api_key=RGAPI-6b21c1fe-67a3-4222-b713-918d6609f30c");
        getRequest.addHeader("accept", "application/json");

        HttpResponse response = httpClient.execute(getRequest);

        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException(
                    "Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output = "";
        System.out.println("Output from Server .... \n");
        /*            while ((output = br.readLine()) != null) {
        System.out.println(output);
        }*/

        do {
            output += br.readLine();
        } while (br.readLine() != null);
        // System.out.println("output: " + output);
        example = new Gson().fromJson(output, PlayerGames.class);
        httpClient.getConnectionManager().shutdown();
        // System.out.println("id: " + example.getSummonerId());
    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();
    }
    return example;
}

From source file:org.androidnerds.reader.util.api.Tags.java

/**
 * This method pulls the tags from Google Reader, its used by the 
 * methods in this class to communicate before parsing the specific
 * results.//ww  w  . ja va2 s  . c o  m
 *
 * @param sid the Google Reader authentication string.
 * @return arr JSONArray of the items from the server.
 */
private static JSONArray pullTags(String sid) {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(URL);
    BasicClientCookie cookie = Authentication.buildCookie(sid);

    try {
        client.getCookieStore().addCookie(cookie);

        HttpResponse response = client.execute(get);
        HttpEntity respEntity = response.getEntity();

        Log.d(TAG, "Response from server: " + response.getStatusLine());

        InputStream in = respEntity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        String line = "";
        String arr = "";
        while ((line = reader.readLine()) != null) {
            arr += line;
        }

        JSONObject obj = new JSONObject(arr);
        JSONArray array = obj.getJSONArray("tags");

        return array;
    } catch (Exception e) {
        Log.d(TAG, "Exception caught:: " + e.toString());
        return null;
    }
}

From source file:br.com.grupofortress.dao.ConectaComFortressRest.java

public JSONObject atualizaVeiculos(String endereco) throws ClientProtocolException, IOException, JSONException {
    HttpClient client = new DefaultHttpClient();

    HttpGet request = new HttpGet(endereco);
    //request.setHeader("ApiKey", apiKey.toString());
    //request.setHeader("SecretKey", secretKey.toString());

    HttpResponse response;//w  w w . j  a  v  a 2 s .c om
    JSONObject dadosFulltrack = null;

    response = client.execute(request);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    String line = "";
    String json = "";

    while ((line = rd.readLine()) != null) {
        json = json + line;
    }

    dadosFulltrack = new JSONObject(json);

    return dadosFulltrack;

}

From source file:com.calmio.calm.integration.Helpers.HTTPHandler.java

public static HTTPResponseData sendGet(String url, String username, String pwd) throws Exception {
    CloseableHttpClient client = HttpClients.custom()
            .setDefaultCredentialsProvider(getCredentialsProvider(url, username, pwd)).build();

    int responseCode = 0;
    StringBuffer respo = null;/*from w w w .  ja  v a  2  s .c  o m*/
    String userPassword = username + ":" + pwd;
    //        String encoding = Base64.getEncoder().encodeToString(userPassword.getBytes());
    String encoding = Base64.encodeBase64String(userPassword.getBytes());

    try {
        HttpGet request = new HttpGet(url);
        request.addHeader("Authorization", "Basic " + encoding);
        request.addHeader("User-Agent", USER_AGENT);
        System.out.println("Executing request " + request.getRequestLine());
        CloseableHttpResponse response = client.execute(request);
        try {
            responseCode = response.getStatusLine().getStatusCode();
            System.out.println("\nSending 'GET' request to URL : " + url);
            System.out.println("Response Code : " + responseCode);
            BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            respo = new StringBuffer();
            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                respo.append(inputLine);
            }
        } finally {
            response.close();
        }
    } finally {
        client.close();
    }

    HTTPResponseData result = new HTTPResponseData(responseCode, ((respo == null) ? "" : respo.toString()));
    System.out.println(result.getStatusCode() + "/n" + result.getBody());
    return result;
}

From source file:javafxapplication1.HttpClientExample.java

String sendGet(String url) throws Exception {

    HttpClient client = new DefaultHttpClient();
    HttpGet request = new HttpGet(url);

    request.addHeader("User-Agent", USER_AGENT);

    HttpResponse response = client.execute(request);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);//from   w  ww .j av a  2s .  c  o  m
    }

    return result.toString();

}

From source file:com.nibss.util.Request.java

public void get(String url) throws Exception {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {/*from  ww w . j  a  va 2 s.  c  o  m*/
        HttpGet httpGet = new HttpGet(url);
        CloseableHttpResponse response1 = httpclient.execute(httpGet);
        try {
            HttpEntity entity1 = response1.getEntity();

            EntityUtils.consume(entity1);
        } finally {
            response1.close();
        }
    } finally {
        httpclient.close();
    }
}

From source file:com.google.resting.rest.client.BaseRESTClient.java

protected static HttpRequest buildHttpRequest(ServiceContext serviceContext) {

    String path = serviceContext.getPath();
    Verb verb = serviceContext.getVerb();
    HttpEntity httpEntity = serviceContext.getHttpEntity();
    List<Header> headers = serviceContext.getHeaders();

    if (verb == Verb.GET) {
        HttpGet httpGet = new HttpGet(path);
        if (headers != null) {
            for (Header header : headers)
                httpGet.addHeader(header);
        }// ww  w.  j a  va  2s  . c  o m
        return httpGet;

    } else if (verb == Verb.POST) {
        HttpPost httpPost = new HttpPost(path);
        if (headers != null) {
            for (Header header : headers)
                httpPost.addHeader(header);
        }
        if (httpEntity != null)
            httpPost.setEntity(httpEntity);
        return httpPost;

    } else if (verb == Verb.DELETE) {
        HttpDelete httpDelete = new HttpDelete(path);
        if (headers != null) {
            for (Header header : headers)
                httpDelete.addHeader(header);
        }
        return httpDelete;

    } else {
        HttpPut httpPut = new HttpPut(path);
        if (headers != null) {
            for (Header header : headers)
                httpPut.addHeader(header);
        }
        if (httpEntity != null)
            httpPut.setEntity(httpEntity);
        return httpPut;
    } //if
}