boolean isValidUrl(String url) { try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection() connection.setRequestMethod('HEAD') if (connection.getResponseCode() == 200) { return true } } catch(final MalformedURLException e) { } catch(final IOException e) { } return false }
Friday, January 29, 2016
HEAD HTTP Request
Tuesday, January 5, 2016
GZip HTTP Request/Response
import java.util.zip.GZIPInputStream String pageUrl = "http://www.google.com" BufferedInputStream buff = pageUrl.toURL().newInputStream(requestProperties: ['Accept-Encoding': 'gzip,deflate']) BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(buff))) String resp = ""; reader.eachLine{ line -> resp += line }
Subscribe to:
Posts (Atom)