List of usage examples for java.net HttpURLConnection setUseCaches
public void setUseCaches(boolean usecaches)
From source file:foam.starwisp.NetworkManager.java
private void Request(String u, String type, String CallbackName) { try {// www . j a va 2 s.c om Log.i("starwisp", "pinging: " + u); URL url = new URL(u); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setUseCaches(false); con.setReadTimeout(100000 /* milliseconds */); con.setConnectTimeout(150000 /* milliseconds */); con.setRequestMethod("GET"); con.setDoInput(true); // Starts the query con.connect(); m_RequestHandler.sendMessage( Message.obtain(m_RequestHandler, 0, new ReqMsg(con.getInputStream(), type, CallbackName))); } catch (Exception e) { Log.i("starwisp", e.toString()); e.printStackTrace(); } }
From source file:de.matzefratze123.heavyspleef.core.uuid.UUIDManager.java
private List<GameProfile> fetchGameProfiles(String[] names) throws IOException, ParseException { List<String> namesList = Arrays.asList(names); URL url = new URL(NAME_BASE_URL); List<GameProfile> profiles = Lists.newArrayList(); int requests = (int) Math.ceil((double) names.length / PROFILES_PER_REQUEST); for (int i = 0; i < requests; i++) { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true);//from w w w .j ava 2s . com connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); String body = JSONArray .toJSONString(namesList.subList(i * 100, Math.min((i + 1) * 100, namesList.size()))); OutputStream out = connection.getOutputStream(); out.write(body.getBytes()); out.flush(); out.close(); InputStream in = connection.getInputStream(); Reader reader = new InputStreamReader(in); JSONArray resultArray = (JSONArray) parser.parse(reader); for (Object object : resultArray) { JSONObject result = (JSONObject) object; String name = (String) result.get("name"); UUID uuid = getUUID((String) result.get("id")); GameProfile profile = new GameProfile(uuid, name); profiles.add(profile); } } return profiles; }
From source file:de.xaniox.heavyspleef.core.uuid.UUIDManager.java
private GameProfile fetchOriginalGameProfile(String name) throws IOException, ParseException { URL url = new URL(String.format(ORIGINAL_NAME_BASE_URL, name.trim())); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true);/*w w w . java 2 s . c om*/ connection.setUseCaches(true); connection.setRequestProperty("Content-Type", "application/json"); InputStream in = connection.getInputStream(); if (in.available() == 0) { return null; } Reader reader = new InputStreamReader(in); JSONObject obj = (JSONObject) parser.parse(reader); UUID uuid = getUUID((String) obj.get("id")); String currentName = (String) obj.get("name"); GameProfile profile = new OriginalGameProfile(uuid, currentName, name); return profile; }
From source file:com.helpmobile.rest.RestAccess.java
public String doGetRequest(String request, Map<String, Object> data, String method) throws MalformedURLException, IOException { StringBuilder postData = new StringBuilder(); for (Map.Entry<String, Object> param : data.entrySet()) { if (postData.length() != 0) { postData.append('&'); }//ww w .j a v a 2 s . co m postData.append(URLEncoder.encode(param.getKey(), "UTF-8")); postData.append('='); postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); } URL path; path = new URL(ADDRESS + request + "?" + postData.toString()); HttpURLConnection conn = (HttpURLConnection) path.openConnection(); conn.setRequestMethod(method); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("AppKey", KEY); conn.setUseCaches(false); conn.setDoInput(true); conn.setRequestProperty("Content-Length", "0"); conn.setDoOutput(true); OutputStream output = conn.getOutputStream(); output.flush(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); conn.disconnect(); //print result return response.toString(); }
From source file:com.adyen.httpclient.HttpURLConnectionClient.java
/** * Initialize the httpConnection// ww w . j a v a 2s. c o m */ private HttpURLConnection createRequest(String requestUrl, String applicationName) throws IOException { URL targetUrl = new URL(requestUrl); HttpURLConnection httpConnection; // Set proxy if configured if (proxy != null) { httpConnection = (HttpURLConnection) targetUrl.openConnection(proxy); } else { httpConnection = (HttpURLConnection) targetUrl.openConnection(); } httpConnection.setUseCaches(false); httpConnection.setDoOutput(true); httpConnection.setRequestMethod("POST"); httpConnection.setRequestProperty("Accept-Charset", CHARSET); httpConnection.setRequestProperty("User-Agent", String.format("%s %s%s", applicationName, Client.USER_AGENT_SUFFIX, Client.LIB_VERSION)); return httpConnection; }
From source file:com.eucalyptus.tokens.oidc.OidcDiscoveryCache.java
private OidcDiscoveryCachedResource fetchResource(final String url, final long timeNow, final OidcDiscoveryCachedResource cached) throws IOException { final URL location = new URL(url); final OidcResource oidcResource; { // setup url connection and resolve final HttpURLConnection conn = (HttpURLConnection) location.openConnection(); conn.setAllowUserInteraction(false); conn.setInstanceFollowRedirects(false); conn.setConnectTimeout(CONNECT_TIMEOUT); conn.setReadTimeout(READ_TIMEOUT); conn.setUseCaches(false); if (cached != null) { if (cached.lastModified.isDefined()) { conn.setRequestProperty(HttpHeaders.IF_MODIFIED_SINCE, cached.lastModified.get()); }//www .j a va2 s . c om if (cached.etag.isDefined()) { conn.setRequestProperty(HttpHeaders.IF_NONE_MATCH, cached.etag.get()); } } oidcResource = resolve(conn); } // build cache entry from resource if (oidcResource.statusCode == 304) { return new OidcDiscoveryCachedResource(timeNow, cached); } else { return new OidcDiscoveryCachedResource(timeNow, Option.of(oidcResource.lastModifiedHeader), Option.of(oidcResource.etagHeader), ImmutableList.copyOf(oidcResource.certs), url, new String(oidcResource.content, StandardCharsets.UTF_8)); } }
From source file:com.baseproject.volley.toolbox.HurlStack.java
/** * Opens an {@link HttpURLConnection} with parameters. * // w ww . j a v a2 s . co m * @param url * @return an open connection * @throws IOException */ private HttpURLConnection openConnection(URL url, Request<?> request) throws IOException { HttpURLConnection connection = createConnection(url); // int timeoutMs = request.getTimeoutMs(); connection.setConnectTimeout(request.getConnTimeoutMs()); connection.setReadTimeout(request.getReadTimeoutMs()); connection.setUseCaches(false); connection.setDoInput(true); // use caller-provided custom SslSocketFactory, if any, for HTTPS if ("https".equals(url.getProtocol()) && mSslSocketFactory != null) { ((HttpsURLConnection) connection).setSSLSocketFactory(mSslSocketFactory); } return connection; }
From source file:com.helpmobile.rest.RestAccess.java
public String doPostRequest(String request, Map<String, Object> data, String method) throws MalformedURLException, IOException { StringBuilder postData = new StringBuilder(); for (Map.Entry<String, Object> param : data.entrySet()) { if (postData.length() != 0) { postData.append('&'); }/*from ww w. j a v a 2s . c om*/ postData.append(URLEncoder.encode(param.getKey(), "UTF-8")); postData.append('='); postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); } URL path; if (method.equalsIgnoreCase(METHOD_GET)) { path = new URL(ADDRESS + request + "?" + postData.toString()); } else { path = new URL(ADDRESS + request); } HttpURLConnection conn = (HttpURLConnection) path.openConnection(); conn.setRequestMethod(method); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("AppKey", KEY); conn.setUseCaches(false); conn.setDoInput(true); if (method.equalsIgnoreCase(METHOD_POST)) { byte[] result = postData.toString().getBytes("UTF-8"); conn.setRequestProperty("Content-Length", Integer.toString(result.length)); conn.setDoOutput(true); OutputStream output = conn.getOutputStream(); output.write(result); output.flush(); } BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); conn.disconnect(); //print result return response.toString(); }
From source file:com.amastigote.xdu.query.module.WaterAndElectricity.java
private Document getPage(String output_data, String host_suffix) throws IOException { URL url = new URL(HOST + host_suffix); HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setDoOutput(true); httpURLConnection.setRequestMethod("POST"); httpURLConnection.setUseCaches(false); httpURLConnection.setInstanceFollowRedirects(false); httpURLConnection.setRequestProperty("Cookie", "ASP.NET_SessionId=" + ASP_dot_NET_SessionId); httpURLConnection.connect();/*from w ww . j ava2 s.co m*/ OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream(), "UTF-8"); outputStreamWriter.write(output_data); outputStreamWriter.flush(); outputStreamWriter.close(); BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(httpURLConnection.getInputStream())); String temp; String htmlPage = ""; while ((temp = bufferedReader.readLine()) != null) htmlPage += temp; bufferedReader.close(); httpURLConnection.disconnect(); htmlPage = htmlPage.replaceAll(" ", " "); return Jsoup.parse(htmlPage); }