Use the universal network framework of j2m's to develop online applications

Source: Internet
Author: User

Although the current wireless network is not ideal, the mobile phone network is still shocking to our developers. After all, this is true.
It's a magic thing, isn't it? This article describes how to use the universal networking framework in the j2-based platform to develop a networked application.
Program.
  
First, it must be noted that, in MIDP, any mobile information device must provide support through http
While other communication methods such as socket are device-related. Some mobile phones are supported, while others are not. Here only
Briefly describe the content related to the http protocol. If you do not know this knowledge, refer to the http protocol. In
Javax. microedition. io contains a large number of interfaces, only one connector class, of course, added in midp2.0
The support for push technology will be discussed later. The most important method provided by the connector class is the open () method. Its
The returned value is Connection. You can convert it to get the type you need. For example, we access the service through http.
.
Void postViaHttpConnection (String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
OutputStream OS = null;
Int rc;
Try {
C = (HttpConnection) Connector. open (url );
// Set the request method and headers
C. setRequestMethod (HttpConnection. POST );
C. setRequestProperty ("If-Modified-Since", "29 Oct 1999 19:43:31 GMT ");
C. setRequestProperty ("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0 ");
C. setRequestProperty ("Content-Language", "en-US ");
// Getting the output stream may flush the headers
OS = c. openOutputStream ();
OS. write ("LIST games". getBytes ());
OS. flush (); // Optional, getResponseCode will flush
// Getting the response code will open the connection,
// Send the request, and read the HTTP response headers.
// The headers are stored until requested.
Rc = c. getResponseCode ();
If (rc! = HttpConnection. HTTP_ OK ){
Throw new IOException ("HTTP response code:" + rc );
}
Is = c. openInputStream ();
// Get the ContentType
String type = c. getType ();
ProcessType (type );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.