MIDP Connectivity
HTTP can either be implemented using IP protocols (such as TCP/IP) or non-IP protocols (such as WAP and i-mode), because the MIDP extends CLDC connectivity to provide support for a subset of the HTTP protocol.
For network programming using MIDP, revert to the HTTP programming model, and the applications will run on any MIDP device, whether it is a GSM phone with a WAP stack, a phone with i-mode, or a Palm VII wireless.
The HttpConnection Interface
The HttpConnection interface is part of the package javax.microedition.io.
It defines the necessary methods and constants for an HTTP connection:
public interface HttpConnection
extends javax.microedition.io.ContentConnection
The HTTP protocol is a request-response application protocol in which the parameters of the request must be set before the request is sent.
The connection could be in one of the three following states:
Setup
: No connection yet
Connected
: Connection has been made, the request has been sent, and some response is expected.
Closed
: Connection is closed.
In the Setup
state, the following methods can be invoked:
public void setRequestMethod( String method )
public void setRequestProperty( String key, String value )
For example, suppose you have this connection:
HttpConnection c = ( HttpConnection )
Connector.open( "http://java.sun.com/developer" );
Then, you can set the request method to be of type POST
as follows:
c.setRequestMethod( HttpConnection.POST );