public class WebUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACCEPT_METHOD |
static WebUtils |
DEFAULT
Creates a new instance of
WebUtils with the default user agent and accept method. |
static java.lang.String |
DEFAULT_AGENT |
| Modifier | Constructor and Description |
|---|---|
protected |
WebUtils(java.lang.String userAgent,
java.lang.String acceptMethod)
Creates a new instance of
WebUtils with the given user agent and accept method. |
| Modifier and Type | Method and Description |
|---|---|
static WebUtils |
create()
Performs a POST request to the given URL with the given input.
|
static WebUtils |
create(java.lang.String userAgent)
Performs a POST request to the given URL with the given input.
|
static WebUtils |
create(java.lang.String userAgent,
java.lang.String acceptMethod)
Performs a POST request to the given URL with the given input.
|
java.lang.String |
get(java.lang.String url)
Performs a GET request to the given URL.
|
static java.lang.String |
performGet(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url)
Performs a POST request to the given URL with the given input.
|
static java.lang.String |
performGet(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> optionalHeaders)
Performs a GET request to the given URL with the given input.
|
static java.lang.String |
performPost(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> optionalHeaders,
java.lang.String... input)
Performs a POST request to the given URL with the given input.
|
static java.lang.String |
performPost(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url,
java.lang.String... input)
Performs a POST request to the given URL with the given input.
|
java.lang.String |
post(java.lang.String url,
java.lang.String... input)
Performs a POST request to the given URL with the given input.
|
WebUtils |
removeHeader(java.lang.String key)
Removes an optional header from the request.
|
WebUtils |
withHeader(java.lang.String key,
java.lang.String value)
Adds an optional header to the request.
|
public static final WebUtils DEFAULT
WebUtils with the default user agent and accept method.public static final java.lang.String DEFAULT_AGENT
public static final java.lang.String ACCEPT_METHOD
protected WebUtils(java.lang.String userAgent,
java.lang.String acceptMethod)
WebUtils with the given user agent and accept method.userAgent - the user agentacceptMethod - the accept methodpublic WebUtils withHeader(java.lang.String key, java.lang.String value)
key - header keyvalue - header valuepublic WebUtils removeHeader(java.lang.String key)
key - header keypublic java.lang.String get(java.lang.String url)
throws java.io.IOException
url - the urljava.io.IOException - if an error occurspublic java.lang.String post(java.lang.String url,
java.lang.String... input)
throws java.io.IOException
url - the urlinput - the inputjava.io.IOException - if an error occurspublic static WebUtils create()
public static WebUtils create(java.lang.String userAgent)
userAgent - the user agentpublic static WebUtils create(java.lang.String userAgent, java.lang.String acceptMethod)
userAgent - the user agentacceptMethod - the accept methodpublic static java.lang.String performGet(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url)
throws java.io.IOException
userAgent - the user agentacceptMethod - the accept methodurl - the urljava.io.IOException - if an error occurspublic static java.lang.String performGet(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> optionalHeaders)
throws java.io.IOException
userAgent - the user agentacceptMethod - the accept methodurl - the urloptionalHeaders - the optional headersjava.io.IOException - if an error occurspublic static java.lang.String performPost(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url,
java.lang.String... input)
throws java.io.IOException
userAgent - the user agentacceptMethod - the accept methodurl - the urlinput - the inputjava.io.IOException - if an error occurspublic static java.lang.String performPost(java.lang.String userAgent,
java.lang.String acceptMethod,
java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> optionalHeaders,
java.lang.String... input)
throws java.io.IOException
userAgent - the user agentacceptMethod - the accept methodurl - the urloptionalHeaders - the optional headersinput - the inputjava.io.IOException - if an error occurs