List of utility methods to do HTTP Response
String | getResponseErrorContent(HttpURLConnection httpConn) Gets the error response as a string if (httpConn.getErrorStream() == null) { return null; } else { StringBuilder sb = new StringBuilder(); BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); String str; while ((str = in.readLine()) != null) { sb.append(str + "\n"); ... |
String | getResponseHeader(HttpURLConnection conn) get Response Header String headerField = conn.getHeaderField(null); if (headerField == null) { return null; StringBuffer sb = new StringBuffer(); sb.append(headerField).append("\r\n"); String key; for (int i = 1; (key = conn.getHeaderFieldKey(i)) != null; i++) { ... |
String | getResponseHeader(String headerName, HttpURLConnection urlConnection) get Response Header return ((HttpURLConnection) urlConnection).getHeaderField(headerName);
|
String | getResponseHeaders(URLConnection conn, HashMap Gets the headers headers.clear(); String responseCode = ""; for (int i = 0;; i++) { String name = conn.getHeaderFieldKey(i); String value = conn.getHeaderField(i); if (name == null && value == null) { break; if (name == null) { responseCode = value; } else { headers.put(name, value); return responseCode; |
String | getResponseMessage(InputStream inputStream, HttpURLConnection connection) get Response Message String responseMessage = null; StringBuffer sb = new StringBuffer(); InputStream dis = connection.getInputStream(); int chr; while ((chr = dis.read()) != -1) { sb.append((char) chr); if (sb != null) { ... |
InputStream | getResponseStream(final HttpURLConnection connection) get Response Stream try { return connection.getInputStream(); } catch (IOException ioe) { InputStream errorStream = connection.getErrorStream(); if (errorStream != null) { return errorStream; throw ioe; ... |
InputStream | getResponseStream(HttpURLConnection conn) Returns the body of the response. return httpOk(conn) ? conn.getInputStream() : conn.getErrorStream();
|
String | getResponseStringFromConn(HttpURLConnection conn, boolean isSuccess) get Response String From Conn BufferedReader reader; if (isSuccess) { reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); } else { reader = new BufferedReader(new InputStreamReader(conn.getErrorStream())); StringBuffer stringBuffer = new StringBuffer(); String line = ""; ... |
String | getResponseText(URL constructedUrl, String encoding) get Response Text HttpURLConnection conn = null; try { conn = (HttpURLConnection) constructedUrl.openConnection(); BufferedReader in = null; if (null == encoding) { in = new BufferedReader(new InputStreamReader(conn.getInputStream())); } else { in = new BufferedReader(new InputStreamReader(conn.getInputStream(), encoding)); ... |
String | getResposeText(HttpURLConnection connection) get Respose Text InputStream is = connection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len; while ((len = is.read(buffer)) > 0) { baos.write(buffer, 0, len); String responseText = baos.toString("UTF8"); ... |