public class Request
extends java.lang.Object
HttpConnection
with definition HTTP request specific fields
and methods. Such as addParameter(), addProperty(), etc.
A HTTP message is a basic unit of HTTP communication,
consisting of a structured sequence of octets matching
the syntax defined in HTTP Message
and transmitted via the connection.
The Request class allows to create an HTTP request, set parameters for
the request URI, set properties for the request and execute it.Modifier and Type | Class and Description |
---|---|
static interface |
Request.Factory
An Interface that represents creating of a request to a server.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CT_URLENCODED
The application/x-www-form-urlencoded content type
|
static java.lang.String |
PROPNM_ACCEPT
The Accept request-header field
|
static java.lang.String |
PROPNM_AUTHORIZATION
The Authorization request-header field
|
static java.lang.String |
PROPNM_CONTENT_TYPE
The Content-Type Entity-header field
|
Constructor and Description |
---|
Request(java.lang.String url)
Creates the request object for required URL.
|
Modifier and Type | Method and Description |
---|---|
void |
addParameter(java.lang.String key,
int value)
Adds a parameter with an integer value to the
query
part of base URL.
|
void |
addParameter(java.lang.String key,
java.lang.String value)
Adds a parameter to the
query
part of the base URL.
|
void |
addProperty(java.lang.String name,
java.lang.String value)
|
protected javax.microedition.io.HttpConnection |
createHttpConnection(java.lang.String uri)
Creates a HTTP connection for the request
|
IResponse |
execute()
The method creates a HttpConnection object,
sets request's parameters
and sends the request to the specified server.
|
byte[] |
getBody()
Returns body of this request
|
java.io.OutputStream |
getBodyOutputStream()
Returns
OutputStream that should be used to form request body. |
java.lang.String |
getMethod()
Returns the method of this request
|
java.lang.String |
getProperty(java.lang.String name)
Returns value of the required property of this request
|
java.lang.String |
getURI()
Returns URI of this request
|
void |
setMethod(java.lang.String method)
Sets request's method ('GET', 'POST', 'PUT', etc.).
|
java.lang.String |
toString()
Returns a string representation of this request.
|
public static final java.lang.String PROPNM_AUTHORIZATION
public static final java.lang.String PROPNM_CONTENT_TYPE
public static final java.lang.String PROPNM_ACCEPT
public static final java.lang.String CT_URLENCODED
public Request(java.lang.String url)
setMethod()
method should be used if it is necessary
to use other request method.url
- a url the request shall be created forpublic void setMethod(java.lang.String method)
method
- method for the request.
By default request uses method 'GET'.
public void addParameter(java.lang.String key, java.lang.String value)
key
- name of the parametervalue
- value of the parameter
NOTE:
value
parameter can be null
. Empty string as a value is equal to
null
value.public void addParameter(java.lang.String key, int value)
key
- name of the parametervalue
- value of the parameterpublic void addProperty(java.lang.String name, java.lang.String value)
name
- name of the propertyvalue
- value of the propertypublic java.io.OutputStream getBodyOutputStream()
OutputStream
that should be used to form request body.protected javax.microedition.io.HttpConnection createHttpConnection(java.lang.String uri) throws java.io.IOException
uri
- required for the requestHttpConnection
for the required urijava.io.IOException
- in case HttpConnection object creation fails.public IResponse execute() throws java.io.IOException
java.io.IOException
- in case the HttpConnection failspublic java.lang.String getMethod()
public java.lang.String getURI()
public java.lang.String getProperty(java.lang.String name)
name
- name of the propertypublic byte[] getBody()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2013, 2014, Oracle and/or its affiliates. All rights reserved.