List of usage examples for org.apache.http.client.methods HttpGet HttpGet
public HttpGet(final String uri)
From source file:com.melchor629.musicote.Utils.java
public static ArrayList getHashMapFromUrl(String url) { //StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); //StrictMode.setThreadPolicy(policy); HashMap map = new HashMap(); try {// www. j a v a 2s . c om long time = System.currentTimeMillis(); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpPost = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); InputStream is = httpEntity.getContent(); //BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF8"), 8192); StringBuilder sb = new StringBuilder(); byte[] buff = new byte[256]; int length = is.read(buff); sb.append(new String(buff, 0, length)); while ((length = is.read(buff)) != -1) { sb.append(new String(buff, 0, length)); } is.close(); Log.d("MainActivity", String.format("JSON Downloaded in %dms", System.currentTimeMillis() - time)); time = System.currentTimeMillis(); Gson gson = new Gson(); String s = sb.toString(); map = gson.fromJson(s, map.getClass()); Log.d("MainActivity", String.format("JSON parsed in %dms", System.currentTimeMillis() - time)); return (ArrayList) map.get("canciones"); } catch (IOException e) { e.printStackTrace(); } catch (IllegalStateException e) { Log.e("Utils", "El archivo recibido no es json"); } return null; }
From source file:dk.kk.ibikecphlib.search.HTTPAutocompleteHandler.java
@SuppressLint("NewApi") public static JsonNode performGET(String urlString) { JsonNode ret = null;//from w w w. jav a 2s. c o m HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, 20000); HttpConnectionParams.setSoTimeout(myParams, 20000); HttpClient httpclient = new DefaultHttpClient(myParams); HttpGet httpget = null; URL url = null; try { url = new URL(urlString); httpget = new HttpGet(url.toString()); LOG.d("Request " + url.toString()); httpget.setHeader("Content-type", "application/json"); HttpResponse response = httpclient.execute(httpget); String serverResponse = EntityUtils.toString(response.getEntity()); LOG.d("Response " + serverResponse); ret = Util.stringToJsonNode(serverResponse); } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return ret; }
From source file:info.smartkit.hairy_batman.demo.MoniterWechatBrowser.java
/** * ?URLhtml?/* w w w . j a va2 s . c om*/ */ @SuppressWarnings("deprecation") public static String getHttpClientHtml(String url, String code, String userAgent) { String html = null; @SuppressWarnings("deprecation") DefaultHttpClient httpClient = new DefaultHttpClient();// httpClient HttpGet httpget = new HttpGet(url);// get?URL // Pause for 4 seconds try { Thread.sleep(5000); } catch (InterruptedException e1) { e1.printStackTrace(); System.out.println(e1.toString()); } // httpget.setHeader("User-Agent", userAgent); try { // responce HttpResponse responce = httpClient.execute(httpget); // ? int returnCode = responce.getStatusLine().getStatusCode(); // 200? ? if (returnCode == HttpStatus.SC_OK) { // HttpEntity entity = responce.getEntity(); if (entity != null) { html = new String(EntityUtils.toString(entity));// html?? } } } catch (Exception e) { System.out.println(""); e.printStackTrace(); } finally { httpClient.getConnectionManager().shutdown(); } return html; }
From source file:org.dataconservancy.ui.it.support.ListPendingRegistrationsRequest.java
public HttpGet asHttpGet() { return new HttpGet(config.getAdminRegistrationUrl().toString()); }
From source file:org.opencastproject.remotetest.server.resource.AdminResources.java
public static HttpResponse recordingsErrors(TrustedHttpClient client) { return client.execute(new HttpGet(getServiceUrl() + "recordings/errors")); }
From source file:nl.mineleni.cbsviewer.jsp.ErrorJSPIntegrationTest.java
/** * testcase voor error.jsp./* w ww . j av a2 s .c o m*/ * * @throws Exception */ @Test @Override public void testIfValidResponse() throws Exception { response = client.execute(new HttpGet(BASE_TEST_URL + "error.jsp")); assertThat("Response status is SC_INTERNAL_SERVER_ERROR.", response.getStatusLine().getStatusCode(), equalTo(SC_INTERNAL_SERVER_ERROR)); boilerplateValidationTests(response); }
From source file:com.skalski.raspberrycontrol.Mjpeg.Mjpeg_InputStream.java
public static Mjpeg_InputStream read(String url) throws IOException { HttpResponse res;//from www. jav a2 s .co m DefaultHttpClient httpclient = new DefaultHttpClient(); res = httpclient.execute(new HttpGet(URI.create(url))); return new Mjpeg_InputStream(res.getEntity().getContent()); }
From source file:org.gbrowser.http.Download.java
public String getPage(String url) throws IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet;/*w w w. j a va 2 s .co m*/ CloseableHttpResponse response1 = null; StringBuilder buff = new StringBuilder(); int ch = -1; try { httpGet = new HttpGet(url.trim()); response1 = httpclient.execute(httpGet); if (response1.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( httpGet.getURI().getPath() + " : " + response1.getStatusLine().getStatusCode() + " : " + response1.getStatusLine().getReasonPhrase()); } System.out.println(response1.getStatusLine()); HttpEntity entity1 = response1.getEntity(); // do something useful with the response body // and ensure it is fully consumed // EntityUtils.consume(entity1); InputStream inp = entity1.getContent(); while ((ch = inp.read()) != -1) { buff.append((char) ch); } } finally { if (response1 != null) { response1.close(); } } return buff.toString(); }
From source file:com.mothsoft.alexis.util.NetworkingUtil.java
public static HttpClientResponse get(final URL url, final String etag, final Date lastModifiedDate) throws IOException { final HttpGet get = new HttpGet(url.toExternalForm()); get.addHeader("Accept-Charset", "UTF-8"); if (etag != null) { get.addHeader("If-None-Match", etag); }/*from ww w . ja v a2s . co m*/ if (lastModifiedDate != null) { get.addHeader("If-Modified-Since", DateUtils.formatDate(lastModifiedDate)); } int statusCode = -1; String responseEtag = null; Date responseLastModifiedDate = null; final HttpClient client = getClient(); HttpResponse response = client.execute(get); statusCode = response.getStatusLine().getStatusCode(); InputStream is = null; Charset charset = null; if (statusCode == 304) { responseEtag = etag; responseLastModifiedDate = lastModifiedDate; } else { final Header responseEtagHeader = response.getFirstHeader("Etag"); if (responseEtagHeader != null) { responseEtag = responseEtagHeader.getValue(); } final Header lastModifiedDateHeader = response.getFirstHeader("Last-Modified"); if (lastModifiedDateHeader != null) { try { responseLastModifiedDate = DateUtils.parseDate(lastModifiedDateHeader.getValue()); } catch (DateParseException e) { responseLastModifiedDate = null; } } final HttpEntity entity = response.getEntity(); // here's where to do intelligent checking of content type, content // length, etc. if (entity.getContentLength() > MAX_CONTENT_LENGTH) { get.abort(); throw new IOException("Exceeded maximum content length, length is: " + entity.getContentLength()); } is = entity.getContent(); charset = getCharset(entity); } return new HttpClientResponse(get, statusCode, responseEtag, responseLastModifiedDate, is, charset); }
From source file:tern.repository.TernRepositoryHelper.java
/** * Load tern modules coming from the given repository.json URL. * // w w w . j a v a 2 s.c o m * @param repositoryURL * repository URL. * @return * @throws IOException * @throws ClientProtocolException * @throws TernException */ public static List<ITernModule> loadModules(String repositoryURL) throws IOException, TernException { // load repository.json with HTTP client. HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(repositoryURL); HttpResponse httpResponse = httpClient.execute(httpGet); HttpEntity entity = httpResponse.getEntity(); InputStream in = entity.getContent(); // Check the status StatusLine statusLine = httpResponse.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode != HttpStatus.SC_OK) { String message = IOUtils.toString(in); if (StringUtils.isEmpty(message)) { throw new TernException(statusLine.toString()); } throw new TernException(message); } // read JSON and create tern modules list JsonObject repository = JsonObject.readFrom(new InputStreamReader(in)); ITernModule module = null; List<ITernModule> modules = new ArrayList<ITernModule>(); for (Member member : repository) { module = new TernModuleToDownload(member.getName(), (JsonObject) member.getValue()); modules.add(module); } return modules; }