List of usage examples for org.apache.http.impl.client DefaultHttpClient execute
public CloseableHttpResponse execute(final HttpUriRequest request) throws IOException, ClientProtocolException
From source file:com.smartsheet.utils.HttpUtils.java
/** * Invokes a HTTP GET and returns the response. *///from w w w .j av a 2 s . c o m private static HttpResponse getResponse(HttpGet httpGet) throws IOException, ClientProtocolException { DefaultHttpClient httpclient = new DefaultHttpClient(); return httpclient.execute(httpGet); }
From source file:com.yojiokisoft.japanesecalc.MyUncaughtExceptionHandler.java
/** * ?????.// www . j a va 2s . c o m */ private static void postBugReport() { List<NameValuePair> nvps = new ArrayList<NameValuePair>(); String bug = getFileBody(sBugReportFile); nvps.add(new BasicNameValuePair("dev", Build.DEVICE)); nvps.add(new BasicNameValuePair("mod", Build.MODEL)); nvps.add(new BasicNameValuePair("sdk", String.valueOf(Build.VERSION.SDK_INT))); nvps.add(new BasicNameValuePair("ver", sVersionName)); nvps.add(new BasicNameValuePair("bug", bug)); try { HttpPost httpPost = new HttpPost("http://mrp-bug-report.appspot.com/bug"); httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.execute(httpPost); } catch (IOException e) { e.printStackTrace(); } sBugReportFile.delete(); }
From source file:Main.java
public static String getResultPost(String uri, List<NameValuePair> params) { String Result = null;/* ww w . ja v a 2 s . c o m*/ try { if (uri == null) { return ""; } HttpPost httpRequest = new HttpPost(uri); BasicHttpParams httpParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParams, REQUEST_TIMEOUT); HttpConnectionParams.setSoTimeout(httpParams, SO_TIMEOUT); DefaultHttpClient httpClient = new DefaultHttpClient(httpParams); httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); HttpResponse httpResponse = httpClient.execute(httpRequest); int res = httpResponse.getStatusLine().getStatusCode(); if (res == 200) { StringBuilder builder = new StringBuilder(); BufferedReader bufferedReader2 = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent())); for (String s = bufferedReader2.readLine(); s != null; s = bufferedReader2.readLine()) { builder.append(s); } Result = builder.toString(); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return Result; }
From source file:com.asksven.betterbatterystats.services.KbReaderService.java
private static InputStream retrieveStream(String url) { DefaultHttpClient client = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); try {//ww w .j av a2 s . com HttpResponse getResponse = client.execute(getRequest); final int statusCode = getResponse.getStatusLine().getStatusCode(); if (statusCode != HttpStatus.SC_OK) { Log.w(TAG, "Error " + statusCode + " for URL " + url); return null; } HttpEntity getResponseEntity = getResponse.getEntity(); return getResponseEntity.getContent(); } catch (IOException e) { getRequest.abort(); Log.w(TAG, "Error for URL " + url, e); } return null; }
From source file:com.alibaba.flink.utils.MetricsMonitor.java
public static Map httpResponse(String url) { Map ret;/*from w w w . j a v a2s . c om*/ try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet(url); 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()); } String data = EntityUtils.toString(response.getEntity()); ret = (Map) Utils.from_json(data); httpClient.getConnectionManager().shutdown(); } catch (IOException e) { ret = errorMsg(e.getMessage()); } return ret; }
From source file:com.sat.common.SDdetails.java
public static void sdStatus(String SDip) throws IOException, FileNotFoundException, ClientProtocolException { new FileOutputStream(htmlfname).close(); htmlfile = new PrintWriter(new BufferedWriter(new FileWriter(htmlfname, true))); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet getRequest = new HttpGet("http://" + SDip + ":2013/service"); HttpResponse response = httpClient.execute(getRequest); BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); String output;/* w w w . ja v a 2 s.com*/ String q = null; System.out.println("SD details .... \n"); while ((output = br.readLine()) != null) { q = output; // System.out.println(output); } httpClient.getConnectionManager().shutdown(); parserGson(q); //htmlfile.close(); }
From source file:co.cask.cdap.gateway.handlers.hooks.MetricsReporterHookTestRun.java
public static HttpResponse doPost(String resource) throws Exception { DefaultHttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(getEndPoint(resource)); post.setHeader(AUTH_HEADER);//from www. ja v a2 s. c om return client.execute(post); }
From source file:com.unitedcoders.android.gpodroid.tools.Tools.java
public static String getImageUrlFromFeed(Context context, String url) { try {//from ww w .ja v a2s. c om Document doc; DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url); HttpResponse response = client.execute(request); doc = builder.parse(response.getEntity().getContent()); // return doc; // get Image NodeList item = doc.getElementsByTagName("channel"); Element el = (Element) item.item(0); String imageUrl; NodeList imagNode = el.getElementsByTagName("image"); if (imagNode != null) { Element ima = (Element) imagNode.item(0); if (ima != null) { NodeList urlNode = ima.getElementsByTagName("url"); if (urlNode == null || urlNode.getLength() < 1) imageUrl = null; else imageUrl = urlNode.item(0).getFirstChild().getNodeValue(); } else imageUrl = null; } else imageUrl = null; return imageUrl; } catch (IOException e) { return null; // The network probably died, just return null } catch (SAXException e) { // Problem parsing the XML, log and return nothing Log.e("NCRSS", "Error parsing XML", e); return null; } catch (Exception e) { // Anything else was probably another network problem, fail silently return null; } }
From source file:net.cs76.projects.student10792819.DrawableManager.java
/** * Fetch.// ww w. ja va2 s . c o m * * @param urlString the url string * @return the input stream * @throws MalformedURLException the malformed url exception * @throws IOException Signals that an I/O exception has occurred. */ private static InputStream fetch(String urlString) throws MalformedURLException, IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(urlString); HttpResponse response = httpClient.execute(request); return response.getEntity().getContent(); }
From source file:com.freedomotic.plugin.purl.Purl.java
private static String readPage(URL url) throws Exception { DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(url.toURI()); HttpResponse response = client.execute(request); Reader reader = null;// w w w.j a v a 2s . c o m try { reader = new InputStreamReader(response.getEntity().getContent()); StringBuilder sb = new StringBuilder(); int read; char[] cbuf = new char[1024]; while ((read = reader.read(cbuf)) != -1) { sb.append(cbuf, 0, read); } return sb.toString(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { //do nothing } } } }