List of utility methods to do URL Connection
String | getPageContent(String inputUrlString) get Page Content URL url = new URL(inputUrlString); return getPageContent(url); |
URL | getRealURL(URL url) Follow redirections for given url. URLConnection connection = url.openConnection(); Map<String, List<String>> header = connection.getHeaderFields(); while (isRedirected(header)) { if (Thread.currentThread().isInterrupted()) { throw new InterruptedException(); url = new URL(header.get("Location").get(0)); connection = url.openConnection(); ... |
long | getRemoteTimestamp(final String url) get Remote Timestamp try { URL u = new URL(url); URLConnection urlc = u.openConnection(); return urlc.getLastModified(); } catch (Exception e) { return -1L; |
void | getRequest(URLConnection conn) get Request if (useStdHeaders) for (int i = 0; i < stdReqHdr.length - 1; i++) conn.setRequestProperty(stdReqHdr[i], stdReqHdr[i + 1]); conn.setDoOutput(true); conn.connect(); |
String | getRequestHeaders(URLConnection conn) get Request Headers StringBuffer headers = new StringBuffer(); String key; int n = 1; headers.append("\n----------\n"); while ((key = conn.getHeaderFieldKey(n)) != null) { String value = conn.getHeaderField(n); headers.append(key + ": " + value + "\n"); n++; ... |
String | getResultsWithEncoding(URLConnection source, String encoding) Download the URL using specified encoding and return contents as a String. InputStreamReader in; if (encoding != null) { in = new InputStreamReader(source.getInputStream(), encoding); } else { in = new InputStreamReader(source.getInputStream()); StringBuilder sb = new StringBuilder(); while (true) { ... |
Reader | getStream(URL url) get Stream URLConnection conn = url.openConnection(); conn.setDefaultUseCaches(false); conn.setUseCaches(false); return new InputStreamReader(conn.getInputStream()); |
URLConnection | getStreamWithTimeOut(String stringUrl, Integer timeOutInMilli) get Stream With Time Out URL url = new URL(stringUrl); URLConnection urlConnection = url.openConnection(); urlConnection.setReadTimeout(timeOutInMilli); urlConnection.setConnectTimeout(timeOutInMilli); return urlConnection; |
String | getString(URL url) get String URLConnection page = url.openConnection(); page.addRequestProperty("User-Agent", USER_AGENT); InputStream is = page.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String result = ""; String line = ""; while ((line = br.readLine()) != null) { result += line + "\r\n"; ... |
String | getType(URLConnection connection) Holt von einer offenen Connection den Mime-Type return connection.getContentType();
|