MTK PlatformUsing Socket to implement the HTTP request process is the content to be introduced in this article, mainly to understand and learnMTK PlatformThroughMTK PlatformTo learnMTK PlatformFor more information, see this article.
I. MTK platform Socket networking process
Anyone familiar with PC programming knows that Socket programming interfaces are divided into two sets: TCP and UDP; TCP and UDP have the concept of server and client, here we will talk about the TCP client programming interface.
To create a Socket on the MTK platform, follow these steps:
1. soc_create) create a Socket;
2. Set soc_setsockopt to the non-blocking mode of Socket;
3. soc_setsockopt sets the Socket option to connection, read, write, and close. It is unclear why it should be set twice in a row;
4. If the CMNET is connected and the English domain name is used in the request, the domain name soc_gethostbyname needs to be resolved. Unless the ip address is used as the domain name, the resolved IP address serves as the target IP address for establishing the connection; if CMWAP is connected to IOT platform, you can directly connect to the China Mobile or China Unicom gateway at 10.0.0.172: 80;
5. Establish a connection between soc_connect and the server;
6. Send a request using soc_send;
7. soc_recv receives the data returned by the server;
8. Close soc_close the Socket;
9. If you need to disable the data account soc_close_nwk_account
Ii. content format of HTTP requests in CMNET or CMWAP Mode
HTTP request format:
GET Method
Request content sent by wap browser in the simulator of MTK Platform
- "GET/go_13596557HTTP/1.1"
- Host: kong.net
- User-Agent: SQH_D480B_01/LB19504/WAP2.0Profile
- Accept: application/vnd. wap. wmlc, ** // (to be long, save the following part)
- Accept-Charset: UTF-8, UTF-16, iso-8859-1, iso-10646-ucs-2, GB2312, windows-1252, us-ascii
- Accept-Language: zh-tw, zh-cn, en
- Cookie: JSESSIONID = aAQP0FIXp3z7
- Connection: Keep-Alive
- "
POST method
For some requests that need to input parameters to the server, search by name and other requests. For weather query in other cities, enter the name or telephone area number of another city:
- "POST/weather/search. jsp? Setcity = 1 https/1.1
-
- Host: kong.net
-
- User-Agent: SQH_D480B_01/LB19504/WAP2.0Profile
-
- Accept: application/vnd. wap. wmlc)
-
- Accept-Charset: UTF-8, UTF-16, iso-8859-1, iso-10646-ucs-2, GB2312, windows-1252, us-ascii
-
- Accept-Language: zh-tw, zh-cn, en
-
- Content-Type: application/x-www-form-urlencoded; charset = UTF-8
-
- Cookie: KONG_ACCESS = AWYZhg =; JSESSIONID = a91MDc6qoMYf
-
- Connection: Keep-Alive
-
- Content-Length: 46 // The get method does not have this item
-
- ×××××× // Transmit the 46-byte data parameter to the server)
-
- "
Of course, if CMWAP is connected to the Internet, the Host and X-Online-Host items must be set in the same way as the above GET method. Host: 10.0.0.172
- X-Online-Host:kong.net
You can run the wap browser of the simulator in the debugging status and insert a breakpoint in the soc_send Method for observation.