List of usage examples for org.apache.http.client.methods HttpGet HttpGet
public HttpGet(final String uri)
From source file:org.zywx.wbpalmstar.engine.eservice.EServiceTest.java
public static void test() { String realyPath = "http://localhost:8000/other.QDV"; HttpRequestBase mHhttpRequest = new HttpGet(realyPath); mHhttpRequest.addHeader("range", "bytes=34199-"); BasicHttpParams bparams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(bparams, 20000); HttpConnectionParams.setSoTimeout(bparams, 20000); HttpConnectionParams.setSocketBufferSize(bparams, 8 * 1024); HttpClientParams.setRedirecting(bparams, true); DefaultHttpClient mDefaultHttpClient = new DefaultHttpClient(bparams); HttpResponse response = null;/*from w w w. j a v a2 s .c o m*/ try { response = mDefaultHttpClient.execute(mHhttpRequest); int responseCode = response.getStatusLine().getStatusCode(); byte[] arrayOfByte = null; HttpEntity httpEntity = response.getEntity(); if (responseCode == 200 || responseCode == 206) { arrayOfByte = toByteArray(httpEntity); String m = new String(arrayOfByte, "UTF-8"); Log.i("ldx", "" + m.length()); Log.i("ldx", m); return; } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.opencastproject.remotetest.server.resource.IngestResources.java
public static HttpResponse createMediaPackage(TrustedHttpClient client) throws Exception { return client.execute(new HttpGet(getServiceUrl() + "createMediaPackage")); }
From source file:com.pcinpact.downloaders.Downloader.java
/** * Tlchargement d'une ressource//from www .j a v a2s .c o m * * @param uneURL * @return */ public static ByteArrayOutputStream download(String uneURL) { // Inspir de http://android-developers.blogspot.de/2010/07/multithreading-for-performance.html AndroidHttpClient client = AndroidHttpClient.newInstance("NextInpact (Unofficial)"); HttpGet getRequest = new HttpGet(uneURL); try { // Lancement de la requte HttpResponse response = client.execute(getRequest); int statusCode = response.getStatusLine().getStatusCode(); // Gestion d'un code erreur if (statusCode != HttpStatus.SC_OK) { if (Constantes.DEBUG) { Log.e("Downloader", "Error " + statusCode + " while retrieving " + uneURL); } return null; } // Chargement de la rponse la requte HttpEntity entity = response.getEntity(); if (entity != null) { // Taille du contenu tlcharger int bufferSize = (int) entity.getContentLength(); // Si erreur ou inconnu, on initialise 1024 if (bufferSize < 0) { bufferSize = 1024; } // Je cre mon buffer ByteArrayOutputStream monBAOS = new ByteArrayOutputStream(bufferSize); try { // Rcupration du contenu entity.writeTo(monBAOS); // Renvoi de ce dernier return monBAOS; } finally { entity.consumeContent(); } } } catch (Exception e) { getRequest.abort(); if (Constantes.DEBUG) { Log.e("Downloader", "Error while retrieving " + uneURL, e); } } finally { if (client != null) { client.close(); } } return null; }
From source file:com.alta189.cyborg.commandkit.util.HttpUtil.java
public static String readURL(String url) { HttpGet request = new HttpGet(url); HttpClient httpClient = new DefaultHttpClient(); try {/* w w w . j a v a 2 s .c o m*/ HttpResponse response = httpClient.execute(request); return EntityUtils.toString(response.getEntity()); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:com.jesjimher.bicipalma.BicipalmaJsonClient.java
public static JSONArray connect(String url) { JSONArray json = new JSONArray(); try {//from w w w. j a va 2 s .com // Primero conectar a la URL base para capturar el id de sesin HttpGet hg = new HttpGet("http://83.36.51.60:8080/eTraffic3/Control?act=mp"); HttpParams httpParameters = new BasicHttpParams(); // Poner los timeouts apropiadamente int timeoutConnection = 5000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = 7000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); DefaultHttpClient hcli = new DefaultHttpClient(httpParameters); HttpResponse resp = hcli.execute(hg); if (resp.getStatusLine().getStatusCode() == 200) { // Con el JSESSIONID, conectar a la URL que recupera el JSON String cookie = resp.getFirstHeader("Set-Cookie").getValue().split(";")[0]; resp.getEntity().consumeContent(); hg = new HttpGet( "http://83.36.51.60:8080/eTraffic3/DataServer?ele=equ&type=401&li=2.6226425170898&ld=2.6837539672852&ln=39.588022779794&ls=39.555621694894&zoom=15&adm=N&mapId=1&lang=es"); hg.setHeader("Referer", "http://83.36.51.60:8080/eTraffic3/Control?act=mp"); hg.addHeader("Cookie", cookie); resp = hcli.execute(hg); if (resp.getStatusLine().getStatusCode() == 200) { HttpEntity he = resp.getEntity(); if (he != null) { // A Simple JSON Response Read InputStream instream = he.getContent(); // Averiguar el encoding String enc = he.getContentType().getValue(); enc = enc.substring(enc.indexOf("charset=") + 8); if (enc.length() <= 0) enc = "ISO-8859-1"; String result = convertStreamToString(instream, enc); json = new JSONArray(result); instream.close(); } resp.getEntity().consumeContent(); } } } catch (IOException e1) { e1.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return json; }
From source file:com.ssy.havefunweb.util.WeixinUtil.java
public static JSONObject doGetStr(String url) throws IOException { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); JSONObject jsonObject = null;/* w w w. j a v a2 s . co m*/ HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); if (entity != null) { String result = EntityUtils.toString(entity, "UTF-8"); jsonObject = JSONObject.fromObject(result); } return jsonObject; }
From source file:com.huguesjohnson.retroleague.util.RestInvoke.java
public static String invoke(String restUrl) throws Exception { String result = null;//from w ww .j a v a2 s .c om HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(restUrl); HttpResponse response = httpClient.execute(httpGet); HttpEntity httpEntity = response.getEntity(); if (httpEntity != null) { InputStream in = httpEntity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuffer temp = new StringBuffer(); String currentLine = null; while ((currentLine = reader.readLine()) != null) { temp.append(currentLine); } result = temp.toString(); in.close(); } return (result); }
From source file:neembuu.release1.settings.OnlineSettingImpl.java
public static String getRaw(String... p) { //Get the version.xml and read the version value. HttpParams params = new BasicHttpParams(); params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6"); DefaultHttpClient httpclient = new DefaultHttpClient(params); String pth = ""; for (String p_ele : p) { pth = pth + "/" + p_ele; }/*from ww w . j a v a2 s.c o m*/ HttpGet httpget = new HttpGet("http://neembuu.sourceforge.net" + pth); LoggerUtil.L().log(Level.INFO, "Getting online setting ...{0}", p); try { HttpResponse response = httpclient.execute(httpget); String respxml = EntityUtils.toString(response.getEntity()); return respxml; } catch (Exception ex) { LoggerUtil.L().log(Level.INFO, "Exception while getting resource " + p, ex); } return null; }
From source file:org.muckebox.android.net.ApiHelper.java
public static String callApi(String query, String id, String[] keys, String[] values) throws IOException, JSONException, AuthenticationException { String str_url = getApiUrl(query, id, keys, values); Log.i(LOG_TAG, "Connecting to " + str_url); MuckeboxHttpClient httpClient = new MuckeboxHttpClient(); HttpGet httpGet = null;//from ww w . j av a2 s. co m try { httpGet = new HttpGet(str_url); HttpResponse httpResponse = httpClient.execute(httpGet); return getResponseAsString(httpResponse); } finally { if (httpGet != null) httpGet.abort(); if (httpClient != null) httpClient.destroy(); } }
From source file:neembuu.uploader.versioning.CheckUser.java
public static void getCanCustomizeNormalizing(UserSetPriv usp) { boolean canCustomizeNormalizing = true; String normalization = ".neembuu"; HttpParams params = new BasicHttpParams(); params.setParameter("http.useragent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6"); HttpClient httpclient = NUHttpClient.getHttpClient(); HttpGet httpget = new HttpGet("http://neembuu.com/uploader/api/user.xml?userid=" + UserImpl.I().uid()); NULogger.getLogger().info("Checking for user priviledges ..."); try {//from ww w .ja va 2s.c o m HttpResponse response = httpclient.execute(httpget); String respxml = EntityUtils.toString(response.getEntity()); canCustomizeNormalizing = getCanCustomizeNormalizingFromXml(respxml); normalization = getNormalization(respxml); NULogger.getLogger().log(Level.INFO, "CanCustomizeNormalizing: {0}", canCustomizeNormalizing); } catch (Exception ex) { NULogger.getLogger().log(Level.INFO, "Exception while checking update\n{0}", ex); } usp.setCanCustomizeNormalizing(canCustomizeNormalizing); usp.setNormalization(normalization); }