Implement WAP and net adaptive in Android

Source: Internet
Author: User
Tags dedicated server

Differences between WAP and net:
(1) why are there two access points?
In the world, there is usually only one GPRS access method. Why are there cmwap and cmnet in China? (The reason why the access point is configured separately for MMS is that the MMS Service needs to connect to a dedicated server, which is not discussed here .)
In fact, cmwap and cmnet are only two GPRS access methods manually divided by China Mobile. The former was set up for mobile WAP Internet access, while the latter mainly used GPRS internet access services for PCs, laptops and PDAs. There is no difference in their implementation methods, but because of their different positioning, cmwap has some restrictions and their charges are also different compared with cmnet.
(2) What is WAP?
WAP is only a GPRS application mode, and it has nothing to do with the GRPS access mode. WAP applications adopt the "terminal + WAP Gateway + WAP Server" mode, which is different from the "terminal + server" Mode on the Internet. The main purpose is to achieve WAP-WEB protocol conversion through WAP gateway to save network traffic and compatibility with existing web applications.
From a technical perspective, the WAP Gateway is only a host that provides the daili service. It is not necessarily provided by network operators. But as far as I know, China Mobile's GPRS network currently only has one WAP Gateway: 10.0.0.172, which is provided by China Mobile for the WAP browsing (HTTP) service. Note that there is a difference between the WAP Gateway and the LAN gateway in the general sense. The standard WAP Gateway only implements the httpdaili function and does not complete the functions of the LAN gateway such as routing and Nat. This determines the restrictions on the application.
(3) China Mobile's limitations on cmwap
China Mobile imposes limits on cmwap to distinguish between the two in applications, mainly because it can only access IP addresses in the GPRS network (10. *. *. *), but cannot access the Internet through routing. (Mobile networks in a few regions may not have this restriction .) We use cmwap to browse Web pages on the Internet through the WAP Gateway Protocol or its httpdaili service.
Speaking of this, it naturally reminds me of the company's network. I believe many working friends have similar experiences. The company's network does not provide routes and Nat on the gateway, but only provides an httpdaili that can access the Internet. In this way, we cannot directly use non-HTTP application software such as QQ and MSN (Fortunately, they also provide httpdaili connection methods ). The same is true for cmwap.
(4) Applicability
The scope of application is the most important concern. Cmnet has full Internet access, which is not mentioned here. Let's take a look at cmwap. With the limitations mentioned above, the applicability of cmwap depends on the support provided by WAP Gateway. Currently, China Mobile's WAP Gateway only provides httpdaili protocol (port 80 and port 8080) and WAP Gateway Protocol (Port 9201 ).
Therefore, only applications that meet the following conditions can work normally in China Mobile's cmwap access mode:
1. Application Program The Network request is based on the HTTP protocol.
2. Applications Support httpdaili or WAP Gateway.
How can I identify whether an application's network request is based on the HTTP protocol?
This is really hard to answer. to fully implement this, we need to analyze the communication packets intercepted by the application. Here we provide a few simple methods for the majority of cainiao friends: in terms of performance, if its network request is in the form of a URL, it is usually based on the HTTP protocol, for example, a Web browser. If the port connecting to the server is port 80, it may be based on the HTTP protocol. If it is true that it cannot be accurately determined, you can directly look at the next condition. (The application meeting the second condition must be based on the HTTP protocol)
How does one differentiate whether an application supports the httpdaili protocol or the WAP gateway protocol?
First, check whether there are any daili server options in its settings (generally, the daili that is not specifically stated on s60 specifically refer to httpdaili). If yes, it indicates that it supports the httpdaili protocol. If not, perform the following steps:
Remove the daili server setting item from the advanced settings of the GPRS access point: server address and server port. If the application can work normally, it is based on the WAP gateway protocol, such as Java programs and s60 built-in browsers. If the daili server settings in the advanced settings of the GPRS connection point fail to work normally, the application supports the httpdaili Protocol (the daili settings are read from the system ). If it still does not work properly, the application generally does not support httpdaili or WAP Gateway.

 

 

Package com. aoran. util;

Import java.net. httpurlconnection;
Import java.net. inetsocketaddress;
Import java.net. url;

/**
* Download Tool
*/
Public class downloadutil {
Private Static final string tag = "downloader ";

/**
* @ Return inputstream download
*/
Public static httpurlconnection download (string URL ){
Httpurlconnection conn = NULL;
Try {
String proxyhost = android.net. Proxy. getdefaulthost ();
If (proxyhost! = NULL) {// if it is a WAP method, add a gateway
Java.net. Proxy P = new java.net. Proxy (java.net. Proxy. type. HTTP, new inetsocketaddress (
Android.net. Proxy. getdefaulthost (), android.net. Proxy. getdefaultport ()));
Conn = (httpurlconnection) new URL (URL). openconnection (P );
} Else {
Conn = (httpurlconnection) new URL (URL). openconnection ();
}
// Conn. setreadtimeout (5000 );
Conn. setconnecttimeout (10000 );
Conn. setrequestmethod ("get ");
Conn. setrequestproperty (
"Accept ",
"Image/GIF, image/JPEG, image/pjpeg, image/pjpeg, application/X-Shockwave-flash, application/XAML + XML, application/vnd. MS-xpsdocument, application/X-MS-xbap, application/X-MS-application, application/vnd. MS-Excel, application/vnd. MS-PowerPoint, application/MSWord ,*/*");
Conn. setrequestproperty ("Accept-language", "ZH-CN ");
Conn. setrequestproperty ("Referer", URL );
Conn. setrequestproperty ("charset", "UTF-8 ");
Conn. setrequestproperty (
"User-Agent ",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0 ;. net CLR 1.1.4322 ;. net CLR 2.0.50727 ;. net CLR 3.0.04506.30 ;. net CLR 3.0.20.6.2152 ;. net CLR 3.5.30729 )");
Conn. setrequestproperty ("connection", "keep-alive ");
Conn. Connect ();
If (conn. getresponsecode () = httpurlconnection. http_ OK ){
Return conn;
}
} Catch (exception e ){
E. printstacktrace ();
}
Return NULL;
}

}

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.