List of utility methods to do HTTP Request
String | request(String httpUrl, Map request return request(httpUrl, httpArgMap, null);
|
List | request(String url, int timeout, String method, Map header) request if (!url.contains("http://") && !url.contains("https://")) url = "http://" + url; URL input = new URL(url); HttpURLConnection connection = (HttpURLConnection) input.openConnection(); connection.setConnectTimeout(timeout); connection.setRequestMethod(method); if (header != null) { for (Object key : header.keySet()) ... |
String | request(String url, Map request HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36"); if (cookies != null && !cookies.isEmpty()) { StringBuilder cookieHeader = new StringBuilder(); for (String cookie : cookies.values()) { if (cookieHeader.length() > 0) { cookieHeader.append(";"); ... |
String | requestData(String url) request Data URL obj; try { obj = new URL(url); } catch (MalformedURLException e) { return ""; HttpURLConnection con; try { ... |
StringBuilder | requestDataFromUrl(URL url, byte[] tosend, String userAgent) request Data From Url HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); if (userAgent != null) { urlConnection.setRequestProperty("User-Agent", userAgent); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.setConnectTimeout(5000); urlConnection.setReadTimeout(20000); ... |
void | saveHttpImage(String requestUrl, String requestMethod, String outputStr, File target) save Http Image try { URL url = new URL(requestUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod(requestMethod); conn.setConnectTimeout(5000); InputStream inStream = conn.getInputStream(); byte[] data = readInputStream(inStream); FileOutputStream outStream = new FileOutputStream(target); ... |
String | sendGet(String url) send Get HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("User-Agent", USER_AGENT); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) response.append(inputLine); ... |
String | sendGet(String url, String param) send Get String result = ""; BufferedReader in = null; HttpURLConnection conn = null; try { String urlNameString = url + "?" + param; URL realUrl = new URL(urlNameString); conn = (HttpURLConnection) realUrl.openConnection(); conn.setConnectTimeout(10000); ... |
HttpURLConnection | sendGetRequest(String requestURL) Makes an HTTP request using GET method to the specified URL. URL url = new URL(requestURL); httpConn = (HttpURLConnection) url.openConnection(); httpConn.setUseCaches(false); httpConn.setDoInput(true); httpConn.setDoOutput(false); return httpConn; |
String | sendGetRequest(String url, String cookies) send Get Request HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestProperty("Cookie", cookies); conn.setRequestProperty("Referer", "http://login.sina.com.cn/signup/signin.php?entry=sso"); conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:34.0) Gecko/20100101 Firefox/34.0"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); BufferedReader read = new BufferedReader(new InputStreamReader(conn.getInputStream(), "gbk")); String line = null; ... |