List of utility methods to do HTTP Read
long | getContentLength(URLConnection con) get Content Length long res = con.getContentLength(); if (res == -1) { try { String str = con.getHeaderField("content-length"); if (str != null) { res = Long.parseLong(str); } catch (Throwable e) { ... |
String | getContents(String urlStr) Invokes URL and get the contents returned. URL url = new URL(urlStr); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); InputStream inputStream = connection.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder builder = new StringBuilder(); String line; while ((line = in.readLine()) != null) { ... |
String | getContentTypeFromUrl(String urlname) get Content Type From Url URL url = new URL(urlname); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); try { connection.setRequestMethod("HEAD"); connection.connect(); return connection.getContentType(); } finally { connection.disconnect(); ... |
String | getContentTypeSpecified(URLConnection connection) get Content Type Specified return connection.getHeaderField(CONTENT_TYPE);
|
String | getContentWithPost(String urls, Map get Content With Post if (pv.isEmpty()) return ""; OutputStreamWriter writer = null; BufferedReader reader = null; try { String body = ""; for (Map.Entry<String, String> entry : pv.entrySet()) { body += entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8") + "&"; ... |
String | getData(String urlString) get Data URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect(); InputStream is = connection.getInputStream(); int i; String incomingMessage = ""; while ((i = is.read()) != -1) { incomingMessage = incomingMessage + (char) i; ... |
byte[] | getHtmlByteArray(final String url) get Html Byte Array URL htmlUrl = null; InputStream inStream = null; try { htmlUrl = new URL(url); URLConnection connection = htmlUrl.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection) connection; int responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { ... |
String | getHtmlContent(String url) get Html Content return getHtmlContent(getConnection(url));
|
InputStream | getInputStream(HttpURLConnection conn) get Input Stream return getInputStream(conn, false);
|
InputStream | getInputStream(HttpURLConnection connection) Gets the correct java.io.InputStream based on urlConnection encoding.
if (connection.getRequestMethod().equals("HEAD")) return null; String encoding = connection.getContentEncoding(); if (encoding == null) return connection.getInputStream(); else if (encoding.equalsIgnoreCase("gzip")) return new GZIPInputStream(connection.getInputStream()); else if (encoding.equalsIgnoreCase("deflate")) ... |