List of utility methods to do HTTP Request
void | addRequestProperties(final Map Copies request properties to a connection. if (requestProperties != null) { for (Entry<String, String> entry : requestProperties.entrySet()) { connection.addRequestProperty(entry.getKey(), entry.getValue()); |
String | doHttpRequest(String action, URL url, String body, String... args) _more_ HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod(action); connection.setRequestProperty("charset", "utf-8"); for (int i = 0; i < args.length; i += 2) { connection.setRequestProperty(args[i], args[i + 1]); ... |
String | getContent(String requestUrl) get Content InputStream inputStream = null; HttpURLConnection httpUrlConn = null; BufferedReader bufferedReader = null; InputStreamReader inputStreamReader = null; try { URL url = new URL(requestUrl); httpUrlConn = (HttpURLConnection) url.openConnection(); httpUrlConn.setDoInput(true); ... |
String | getDataFromRequestViaPost(String request, String urlParameters) Gets data using HTTP POST method. HttpURLConnection con = (HttpURLConnection) new URL(request).openConnection(); con.setDoOutput(true); con.setDoInput(true); con.setInstanceFollowRedirects(false); con.setRequestMethod("POST"); con.setRequestProperty("charset", "utf-8"); con.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length)); con.setUseCaches(false); ... |
String | getOutputFromUrlConnection(String stringUrl, String requestProperty) get Output From Url Connection String outputString = null; try { URL url = new URL(stringUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", requestProperty); conn.connect(); if (conn.getResponseCode() != 200) { ... |
String | getRequest(String urlString) get Request StringBuilder result = new StringBuilder(); URL url = null; BufferedReader rd = null; HttpURLConnection conn = null; try { url = new URL(urlString); } catch (MalformedURLException e) { e.printStackTrace(); ... |
HttpURLConnection | getRequest(URL url, int timeout) get Request HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(timeout); conn.setReadTimeout(timeout); return conn; |
String | getRequestContent(String urlText) get Request Content URL url = new URL(urlText); HttpURLConnection urlcon = (HttpURLConnection) url.openConnection(); urlcon.setRequestMethod("POST"); urlcon.setUseCaches(false); urlcon.setDoOutput(true); PrintStream ps = new PrintStream(urlcon.getOutputStream()); ps.close(); urlcon.connect(); ... |
String | makeUrlRequest(String surl, String data, String method) make Url Request URL url = new URL(surl); HttpURLConnection con; con = (HttpURLConnection) url.openConnection(); con.setRequestMethod(method); con.setRequestProperty("User-Agent", "EBA Client"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); ... |
void | request(boolean quiet, String method, URL url, Map request if (!quiet) { System.out.println("[issuing request: " + method + " " + url + "]"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod(method); byte buffer[] = new byte[8192]; int read = 0; if (body != null) { ... |