public class JavaHttpRequest extends HttpRequest
Modifier and Type | Class and Description |
---|---|
static class |
JavaHttpRequest.JavaHttpRequestFactory |
HttpRequest.HttpRequestFactory
HEADER_ACCEPT, HEADER_CONTENT_LENGTH, HEADER_CONTENT_TYPE, HEADER_USER_AGENT, METHOD_DELETE, METHOD_GET, METHOD_POST, METHOD_PUT
Constructor and Description |
---|
JavaHttpRequest(java.lang.String url) |
Modifier and Type | Method and Description |
---|---|
OutputStream |
createRequestBodyStream()
Returns an output stream that writes to this connection.
|
java.lang.String |
getHeader(java.lang.String name)
Returns the value of the named header or null if it's not set.
|
HttpResponse |
send()
Opens a communications link to the resource referenced by this URL, if such a connection has not already been
established.
|
void |
setHeader(java.lang.String name,
java.lang.String value)
Sets the specified HTTP request header to the specified value.
|
void |
setMethod(java.lang.String method)
Set the method for the request, one of:
GET POST HEAD OPTIONS PUT DELETE TRACE
are legal, subject to protocol restrictions.
|
void |
setTimeout(int timeoutInMillis)
Sets a specified timeout value, in milliseconds, to be used when doing connecting/reading/writing to the server.
|
create, setContentTypeAndAcceptHeaders, setFactory
public void setMethod(java.lang.String method)
HttpRequest
setMethod
in class HttpRequest
method
- the HTTP methodpublic void setTimeout(int timeoutInMillis)
HttpRequest
setTimeout
in class HttpRequest
timeoutInMillis
- an int
that specifies the connect timeout value in millisecondspublic void setHeader(java.lang.String name, java.lang.String value)
HttpRequest
setHeader
in class HttpRequest
name
- the header name (e.g., "Accept
")value
- the value associated with itpublic java.lang.String getHeader(java.lang.String name)
HttpRequest
getHeader
in class HttpRequest
name
- the header name (e.g., "Accept").public OutputStream createRequestBodyStream()
HttpRequest
createRequestBodyStream
in class HttpRequest
public HttpResponse send()
HttpRequest
connect
method is called when the connection has already been opened.
HttpRequest objects go through two phases: first they are created, then they are connected. After being created,
and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it
is an error to try to set them. Operations that depend on being connected, like getContentLength, will
implicitly perform the connection, if necessary.send
in class HttpRequest
HttpRequest.setTimeout(int)