public final class UrlUtilities extends Object
Modifier and Type | Field and Description |
---|---|
static String |
COOKIE |
static String |
COOKIE_VALUE_DELIMITER |
static SafeSimpleDateFormat |
DATE_FORMAT |
static char |
DOT |
static String |
EXPIRES |
static TrustManager[] |
NAIVE_TRUST_MANAGER |
static HostnameVerifier |
NAIVE_VERIFIER |
static char |
NAME_VALUE_SEPARATOR |
static String |
PATH |
static String |
SET_COOKIE |
static String |
SET_COOKIE_SEPARATOR |
Modifier and Type | Method and Description |
---|---|
static SSLSocketFactory |
buildNaiveSSLSocketFactory() |
static void |
disconnect(HttpURLConnection c) |
static URL |
getActualUrl(String url) |
static URLConnection |
getConnection(String url,
boolean input,
boolean output,
boolean cache) |
static URLConnection |
getConnection(URL url,
boolean input,
boolean output,
boolean cache) |
static URLConnection |
getConnection(URL url,
Map inCookies,
boolean input,
boolean output,
boolean cache,
Proxy proxy,
SSLSocketFactory socketFactory,
HostnameVerifier verifier) |
static URLConnection |
getConnection(URL url,
String proxyServer,
int port,
Map inCookies,
boolean input,
boolean output,
boolean cache,
boolean ignoreSec) |
static byte[] |
getContentFromUrl(String url)
Get content from the passed in URL.
|
static byte[] |
getContentFromUrl(String url,
Map inCookies,
Map outCookies,
Proxy proxy,
SSLSocketFactory factory,
HostnameVerifier verifier)
Get content from the passed in URL.
|
static byte[] |
getContentFromUrl(String url,
Proxy proxy)
Get content from the passed in URL.
|
static byte[] |
getContentFromUrl(String url,
Proxy proxy,
SSLSocketFactory factory,
HostnameVerifier verifier)
Get content from the passed in URL.
|
static byte[] |
getContentFromUrl(String url,
String proxyServer,
int port,
Map inCookies,
Map outCookies,
boolean ignoreSec)
Get content from the passed in URL.
|
static String |
getContentFromUrlAsString(String url)
Get content from the passed in URL.
|
static String |
getContentFromUrlAsString(String url,
Proxy proxy)
Get content from the passed in URL.
|
static String |
getContentFromUrlAsString(String url,
String proxyServer,
int port,
Map inCookies,
Map outCookies,
boolean ignoreSec)
Get content from the passed in URL.
|
static String |
getCookieDomainFromHost(String host) |
static void |
getCookies(URLConnection conn,
Map store)
Retrieves and stores cookies returned by the host on the other side of
the open java.net.URLConnection.
|
static String |
getHostName() |
static String |
getUserAgent() |
static void |
readErrorResponse(URLConnection c) |
static void |
setCookies(URLConnection conn,
Map store)
Prior to opening a URLConnection, calling this method will set all
unexpired cookies that match the path or subpaths for thi underlying URL
The connection MUST NOT have been opened
method or an IOException will be thrown.
|
static void |
setReferrer(String referrer) |
static void |
setTimeouts(URLConnection c,
int read,
int connect) |
static void |
setUserAgent(String userAgent) |
public static final String SET_COOKIE
public static final String COOKIE_VALUE_DELIMITER
public static final String PATH
public static final String EXPIRES
public static final SafeSimpleDateFormat DATE_FORMAT
public static final String SET_COOKIE_SEPARATOR
public static final String COOKIE
public static final char NAME_VALUE_SEPARATOR
public static final char DOT
public static final TrustManager[] NAIVE_TRUST_MANAGER
public static final HostnameVerifier NAIVE_VERIFIER
public static void setReferrer(String referrer)
public static void setUserAgent(String userAgent)
public static String getUserAgent()
public static URLConnection getConnection(String url, boolean input, boolean output, boolean cache) throws IOException
IOException
public static URLConnection getConnection(URL url, boolean input, boolean output, boolean cache) throws IOException
IOException
public static void setTimeouts(URLConnection c, int read, int connect)
public static void readErrorResponse(URLConnection c)
public static void disconnect(HttpURLConnection c)
public static void getCookies(URLConnection conn, Map store)
conn
- a java.net.URLConnection - must be open, or IOException will
be thrownpublic static void setCookies(URLConnection conn, Map store) throws IOException
conn
- a java.net.URLConnection - must NOT be open, or IOException will be thrownIOException
- Thrown if conn has already been opened.public static String getContentFromUrlAsString(String url, Proxy proxy)
url
- URL to hitproxy
- proxy to use to create connectionpublic static String getContentFromUrlAsString(String url)
url
- URL to hitpublic static byte[] getContentFromUrl(String url)
url
- URL to hitpublic static byte[] getContentFromUrl(String url, Proxy proxy)
url
- URL to hitproxy
- proxy to use to create connectionpublic static String getContentFromUrlAsString(String url, String proxyServer, int port, Map inCookies, Map outCookies, boolean ignoreSec)
url
- URL to hitproxyServer
- String named of proxy serverport
- port to access proxy serverinCookies
- Map of session cookies (or null if not needed)outCookies
- Map of session cookies (or null if not needed)ignoreSec
- if true, SSL connection will always be trusted.public static byte[] getContentFromUrl(String url, Proxy proxy, SSLSocketFactory factory, HostnameVerifier verifier)
url
- URL to hitproxy
- Proxy server to create connection (or null if not needed)factory
- custom SSLSocket factory (or null if not needed)verifier
- custom Hostnameverifier (or null if not needed)public static byte[] getContentFromUrl(String url, Map inCookies, Map outCookies, Proxy proxy, SSLSocketFactory factory, HostnameVerifier verifier)
url
- URL to hitinCookies
- Map of session cookies (or null if not needed)outCookies
- Map of session cookies (or null if not needed)proxy
- Proxy server to create connection (or null if not needed)factory
- custom SSLSocket factory (or null if not needed)verifier
- custom Hostnameverifier (or null if not needed)public static byte[] getContentFromUrl(String url, String proxyServer, int port, Map inCookies, Map outCookies, boolean ignoreSec)
url
- URL to hitproxyServer
- String named of proxy serverport
- port to access proxy serverinCookies
- Map of session cookies (or null if not needed)outCookies
- Map of session cookies (or null if not needed)ignoreSec
- if true, SSL connection will always be trusted.public static SSLSocketFactory buildNaiveSSLSocketFactory()
public static URLConnection getConnection(URL url, Map inCookies, boolean input, boolean output, boolean cache, Proxy proxy, SSLSocketFactory socketFactory, HostnameVerifier verifier) throws IOException
IOException
public static URLConnection getConnection(URL url, String proxyServer, int port, Map inCookies, boolean input, boolean output, boolean cache, boolean ignoreSec) throws IOException
IOException
public static String getHostName()
public static URL getActualUrl(String url) throws MalformedURLException
MalformedURLException
Copyright © 2014. All rights reserved.