List of utility methods to do HTTP Read
String | readError(HttpURLConnection conn) _more_ try { return readString(new BufferedReader(new InputStreamReader(conn.getErrorStream(), "UTF-8"))); } catch (Exception exc) { return "No error message"; |
String | readGetEx(String url) read Get Ex String res = ""; BufferedReader reader = null; try { HttpURLConnection conn; conn = (HttpURLConnection) (new URL(url)).openConnection(); reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = reader.readLine()) != null) ... |
String | readHTTPConnection(HttpURLConnection conn) read HTTP Connection StringBuilder sb = new StringBuilder(); BufferedReader br; br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8")); String line = null; while ((line = br.readLine()) != null) { sb.append(line + "\n"); br.close(); ... |
byte[] | readHttpConnection(HttpURLConnection h) read Http Connection ArrayList<Byte> a = new ArrayList<Byte>(100); InputStream is = h.getInputStream(); int i = is.read(); while (i != -1) { a.add((byte) i); i = is.read(); byte b[] = new byte[a.size()]; ... |
byte[] | readHttpFile(String fileUrl, String referer) read Http File InputStream inputStream = null; ByteArrayOutputStream fileContent = null; try { URL url = new URL(fileUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (referer != null) { connection.setRequestProperty("Referer", referer); inputStream = connection.getInputStream(); fileContent = new ByteArrayOutputStream(); byte[] buffer = new byte[FILE_READ_BUFFER_SIZE]; int n = 0; while (-1 != (n = inputStream.read(buffer))) { fileContent.write(buffer, 0, n); } finally { if (inputStream != null) { inputStream.close(); if (fileContent != null) { fileContent.close(); return fileContent.toByteArray(); |
String | readRaw(URL url) Convenience method for reading a JSON string from a URL HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setReadTimeout(5000); connection.setConnectTimeout(5000); connection.setRequestProperty("User-Agent", "Mozilla/5.0"); connection.addRequestProperty("Content-Type", "application/json"); connection.addRequestProperty("Accept", "application/json"); BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder content = new StringBuilder(); ... |