List of usage examples for org.apache.http.client.methods HttpGet HttpGet
public HttpGet(final String uri)
From source file:core.RESTCalls.RESTGet.java
public static InputStream httpGetResponse(String urlStr) { InputStream inputStream = null; try {/* w ww . j ava2 s . c om*/ HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(urlStr); HttpResponse response = client.execute(get); inputStream = response.getEntity().getContent(); } catch (Exception ex) { ex.printStackTrace(); } return inputStream; }
From source file:net.sf.arbocdi.ser.requester.ApacheRequester.java
@Override public String makeRequest(String request) throws Exception { HttpGet getRequest = new HttpGet(request); return this.httpClientWrapper.makeStringRequest(getRequest); }
From source file:uk.org.todome.Util.java
public static String getFileFromServer(String request) { StringBuilder builder = new StringBuilder(); HttpClient client = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(request); Log.i("Util.getFileFromServer", "Request used: " + request); try {/* w w w .j av a 2s .c om*/ HttpResponse response = client.execute(httpGet); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(content)); String line; while ((line = reader.readLine()) != null) { builder.append(line); } } else { Log.e("", "Failed to download file"); } } catch (Exception ex) { Log.e("Util.getFileFromServer", ex.getClass().toString() + " " + ex.getMessage()); } return builder.toString(); }
From source file:it410.gmu.edu.OrderingServiceClient.java
public static void getCustomersJSON() throws Exception { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet("http://localhost:8080/BookstoreRestService/generic/getOrdersJSON"); HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; StringBuilder sb = new StringBuilder(); while ((line = rd.readLine()) != null) { //System.out.println(line); sb.append(line);/*w w w . j a v a 2s .co m*/ } System.out.println("Customers JSON = " + sb.toString()); Gson gson = new Gson(); Customers customers = gson.fromJson(new StringReader(sb.toString()), Customers.class); System.out.println(" JSON Customer List size = " + customers.getCustomersJSON().size()); }
From source file:org.thoughtcrime.securesms.mms.MmsDownloadHelper.java
private static byte[] makeRequest(MmsConnectionParameters connectionParameters, String url) throws ClientProtocolException, IOException { try {/*from w w w . jav a2s .c o m*/ HttpClient client = constructHttpClient(connectionParameters); URI hostUrl = new URI(url); HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); HttpRequest request = new HttpGet(url); request.setParams(client.getParams()); request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); HttpResponse response = client.execute(target, request); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase()); return parseResponse(response.getEntity()); } catch (URISyntaxException use) { Log.w("MmsDownlader", use); throw new IOException("Bad URI syntax"); } }
From source file:shootersubdownloader.Shootersubdownloader.java
private static void down(File f) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); String url = String.format("https://www.shooter.cn/api/subapi.php?filehash=%s&pathinfo=%s&format=json", computefilehash(f), f.getName()); System.out.println(url);//from w ww. j a v a 2 s .c o m HttpGet request = new HttpGet(url); CloseableHttpResponse r = httpclient.execute(request); System.out.println(r.getStatusLine()); HttpEntity e = r.getEntity(); String s = EntityUtils.toString(e); System.out.println(s); JSONArray json = JSONArray.fromObject(s); // JSONObject json = JSONObject.fromObject(s); System.out.println(json.size()); for (int i = 0; i < json.size(); i++) { System.out.println(i); JSONObject obj = json.getJSONObject(i); JSONArray fs = obj.getJSONArray("Files"); String downurl = fs.getJSONObject(0).getString("Link"); HttpGet r2 = new HttpGet(downurl); CloseableHttpResponse res2 = httpclient.execute(r2); // Header[] headers = res2.getAllHeaders(); // for(Header h:headers){ // System.out.println(h.getName()); // System.out.println(h.getValue()); // } Header header = res2.getFirstHeader("Content-Disposition"); String sig = "filename="; String v = header.getValue(); String fn = v.substring(v.indexOf(sig) + sig.length()); HttpEntity e2 = res2.getEntity(); File outf = new File(fn); FileOutputStream fos = new FileOutputStream(outf); e2.writeTo(fos); System.out.println(filecharsetdetect.FileCharsetDetect.detect(outf)); // res2.getEntity().writeTo(new FileOutputStream(fn)); System.out.println(fn); res2.close(); } r.close(); httpclient.close(); }
From source file:org.opencastproject.remotetest.server.resource.AdminResources.java
public static HttpResponse recordingsFinished(TrustedHttpClient client) { return client.execute(new HttpGet(getServiceUrl() + "recordings/finished")); }
From source file:org.fdroid.enigtext.mms.MmsDownloadHelper.java
private static byte[] makeRequest(Context context, MmsConnectionParameters connectionParameters, String url) throws IOException { AndroidHttpClient client = null;//w w w .ja va 2 s.c o m try { client = constructHttpClient(context, connectionParameters); URI targetUrl = new URI(url.trim()); HttpHost target = new HttpHost(targetUrl.getHost(), targetUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); HttpGet request = new HttpGet(url.trim()); request.setParams(client.getParams()); request.addHeader("Accept", "*/*, application/vnd.wap.mms-message, application/vnd.wap.sic"); HttpResponse response = client.execute(target, request); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) throw new IOException("Non-successful HTTP response: " + status.getReasonPhrase()); return parseResponse(response.getEntity()); } catch (URISyntaxException use) { Log.w("MmsDownloadHelper", use); throw new IOException("Couldn't parse URI"); } finally { if (client != null) client.close(); } }
From source file:com.safecell.networking.GetLicenseKey.java
public String getRequest() { HttpClient client = new DefaultHttpClient(); HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout String url = URLs.REMOTE_URL + "api/1/license_classes"; HttpGet postRequest = new HttpGet(url); postRequest.setHeader("Content-Type", "application/json"); String result = null;/*from w w w . ja v a 2 s . c o m*/ try { response = client.execute(postRequest); result = getResponseBody(); if (response.getStatusLine().getStatusCode() != 200) { response = null; result = null; failureMessage = "The licenses downlaod failed because of an unexpected error."; } } catch (Exception e) { response = null; result = null; failureMessage = "The licenses downlaod failed because of an unexpected error."; } return result; }
From source file:org.opencastproject.remotetest.server.resource.CaptureResources.java
public static HttpResponse stopCapture(TrustedHttpClient client) { return client.execute(new HttpGet(getServiceUrl() + "stopCapture")); }