Introduction to HTTP request process using Socket on MTK platform (1)

Source: Internet
Author: User

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

 
  1. "GET/go_13596557HTTP/1.1"
  2. Host: kong.net
  3. User-Agent: SQH_D480B_01/LB19504/WAP2.0Profile
  4. Accept: application/vnd. wap. wmlc, ** // (to be long, save the following part)
  5. Accept-Charset: UTF-8, UTF-16, iso-8859-1, iso-10646-ucs-2, GB2312, windows-1252, us-ascii
  6. Accept-Language: zh-tw, zh-cn, en
  7. Cookie: JSESSIONID = aAQP0FIXp3z7
  8. Connection: Keep-Alive
  9. "

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:

 
  1. "POST/weather/search. jsp? Setcity = 1 https/1.1
  2.  
  3. Host: kong.net
  4.  
  5. User-Agent: SQH_D480B_01/LB19504/WAP2.0Profile
  6.  
  7. Accept: application/vnd. wap. wmlc)
  8.  
  9. Accept-Charset: UTF-8, UTF-16, iso-8859-1, iso-10646-ucs-2, GB2312, windows-1252, us-ascii
  10.  
  11. Accept-Language: zh-tw, zh-cn, en
  12.  
  13. Content-Type: application/x-www-form-urlencoded; charset = UTF-8
  14.  
  15. Cookie: KONG_ACCESS = AWYZhg =; JSESSIONID = a91MDc6qoMYf
  16.  
  17. Connection: Keep-Alive
  18.  
  19. Content-Length: 46 // The get method does not have this item
  20.  
  21. ×××××× // Transmit the 46-byte data parameter to the server)
  22.  
  23. "

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

 
  1. 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.


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.