Call the HTTP interface of Apsara to send text messages to you and call the interface to send text messages.

Source: Internet
Author: User

Call the HTTP interface of Apsara to send text messages to you and call the interface to send text messages.

Note:

1. All the hosts referred to in the following HTTP requests are f.10086.cn

2. Currently, only China Mobile users can use

1. Open the logon page: GET/huc/user/space/login. do? M = submit & fr = space, get two cookie values: JSESSIONID and UUID
2. Logon: POST/huc/user/space/login. do, the data is the mobile phone number and password: mobilenum = your_phone_number & password = your_fetioon_password & m = submit & backurl = http % 3A % 2F % 2Ff.10086.cn % 2F & fr = space, obtain the cookie value: Set-Cookie: cell_cookie. Note: When Logging On, you must carry the header: Content-Type: application/x-www-form-urlencoded. Otherwise, the verification code check is triggered.
2.1 The above step 2 will redirect to another path: Location: http://f.10086.cn /? Nuc_id = 5cb9e9eca65e2bc2875a6fe55869daa1, 4e8cbe602e50b189ddc33e51de704474, e017a7e72b081563f1fbf1263d2fd8f8
2.2, http://f.10086.cn /? Nuc_id = 5cb9e9eca65e2bc2875a6fe55869daa1, large, e017a7e72b081563f1fbf1263d2fd8f8, 1 <---- This will continue to redirect to Location: Large. Wap2.jsp is a comprehensive news webpage.
3. Send A message: POST/im/user/sendMsgToMyselfs. action HTTP/1.1; Data: msg = A hello word short message
3.1 The above steps may be redirected to Location: http://f.10086.cn/im/login/cklogin.action? T = 1420875966727. At this time, you can re-POST/im/user/sendMsgToMyselfs. action HTTP/1.1 to send the message successfully.

 

The Demo is implemented using MFC Wininet. You can still send text messages when publishing this article.

In addition, the Code has not been refined. Do not worry about bugs such as memory leaks...

# Define FE_BUFFER_SIZE (1024*1024) void do_me () {HINTERNET hSessHnd; HINTERNET hConnHnd; HINTERNET hRqstHnd; BOOL bRqstRet; BOOL bQueryRet; BOOL bReadRet; UCHAR * pucBuffer = new UCHAR [FE_BUFFER_SIZE]; DWORD dwBufferLen; DWORD dwReadLen; DWORD dwIndex; // use the fiddler proxy hSessHnd = InternetOpenA ("FetionMsg", expires, "http = http: // 127.0.0.1: 8888 ", NULL, 0); // log on directly // hSessHnd = InternetOpen A ("FetionMsg", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); if (NULL = hSessHnd) {printf ("InternetOpenA failed \ r \ n"); return ;} hConnHnd = InternetConnectA (hSessHnd, "f.10086.cn", region, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); if (NULL = hConnHnd) {printf ("InternetConnectA failed. \ r \ n "); return;} hRqstHnd = HttpOpenRequestA (hConnHnd," GET "," huc/user/space/login. do? M = submit & fr = space "," HTTP/1.1 ", NULL, NULL, INTERNET_FLAG_RELOAD, 0); if (NULL = hRqstHnd) {printf (" HttpOpenRequestA failed. \ r \ n "); return;} bRqstRet = HttpSendRequestA (hRqstHnd, NULL, 0, NULL, 0); if (TRUE! = BRqstRet) {printf ("HttpSendRequestA failed \ r \ n"); return;} ZeroMemory (pucBuffer, buffers); dwBufferLen = bytes; dwIndex = 0; bQueryRet = HttpQueryInfoA (hRqstHnd, HTTP_QUERY_CONTENT_LENGTH, pucBuffer, & dwBufferLen, & dwIndex); if (TRUE = bQueryRet) {printf ("1: len = % s, % u \ r \ n", pucBuffer, dwBufferLen); bReadRet = InternetReadFile (hRqstHnd, pucBuffer, FE_BUFFER_SIZE, & dwReadLen); Printf ("1 read ret = % u, len = % u \ r \ n", bReadRet, dwReadLen); printf ("-------- \ r \ n "); printf ("% s", pucBuffer); printf ("-------- \ r \ n");} else {printf ("1 no response body \ r \ n ");} internetCloseHandle (hRqstHnd); hRqstHnd = HttpOpenRequestA (hConnHnd, "POST", "huc/user/space/login. do "," HTTP/1.1 ", NULL, NULL, INTERNET_FLAG_RELOAD, 0); if (NULL = hRqstHnd) {printf (" HttpOpenRequestA 2 failed. \ r \ n "); re Turn;} HttpAddRequestHeadersA (hRqstHnd, "Content-Type: application/x-www-form-urlencoded \ r \ n",-1, HTTP_ADDREQ_FLAG_ADD ); const char * pcLoginData = "mobilenum = your_number & password = your_fetion_password & m = submit & backurl = http % 3A % 2F % 2Ff.10086.cn % 2F & fr = space "; bRqstRet = HttpSendRequestA (hRqstHnd, NULL, 0, (VOID *) pcLoginData, strlen (pcLoginData); if (TRUE! = BRqstRet) {printf ("HttpSendRequestA 2 failed \ r \ n"); return;} ZeroMemory (pucBuffer, FE_BUFFER_SIZE); dwBufferLen = FE_BUFFER_SIZE; dwIndex = 0; bQueryRet = HttpQueryInfoA (hRqstHnd, HTTP_QUERY_CONTENT_LENGTH, pucBuffer, & dwBufferLen, & dwIndex); if (TRUE = bQueryRet) {printf ("2: len = % s, % u \ r \ n ", pucBuffer, dwBufferLen); bReadRet = InternetReadFile (hRqstHnd, pucBuffer, FE_BUFFER_SIZE, & dwReadLe N); printf ("2 read ret = % u, len = % u \ r \ n", bReadRet, dwReadLen); printf ("-------- \ r \ n "); printf ("% s", pucBuffer); printf ("-------- \ r \ n");} else {printf ("2 no response body \ r \ n ");} internetCloseHandle (hRqstHnd); hRqstHnd = HttpOpenRequestA (hConnHnd, "POST", "im/user/sendMsgToMyselfs. action "," HTTP/1.1 ", NULL, NULL, 0, 0); if (NULL = hRqstHnd) {printf (" HttpOpenRequestA 3 failed. \ r \ n "); return;} c Onst char * pcMsgData = "msg = HelloWorld"; bRqstRet = HttpSendRequestA (hRqstHnd, NULL, 0, (VOID *) pcMsgData, strlen (pcMsgData); if (TRUE! = BRqstRet) {printf ("HttpSendRequestA 3 failed \ r \ n"); return;} ZeroMemory (pucBuffer, FE_BUFFER_SIZE); dwBufferLen = FE_BUFFER_SIZE; dwIndex = 0; bQueryRet = HttpQueryInfoA (hRqstHnd, HTTP_QUERY_CONTENT_LENGTH, pucBuffer, & dwBufferLen, & dwIndex); if (TRUE = bQueryRet) {printf ("3: len = % s, % u \ r \ n ", pucBuffer, dwBufferLen); bReadRet = InternetReadFile (hRqstHnd, pucBuffer, FE_BUFFER_SIZE, & dwReadLe N); printf ("3 read ret = % u, len = % u \ r \ n", bReadRet, dwReadLen); printf ("-------- \ r \ n "); printf ("% s", pucBuffer); printf ("-------- \ r \ n");} else {printf ("3 no response body \ r \ n ");} internetCloseHandle (hRqstHnd); hRqstHnd = HttpOpenRequestA (hConnHnd, "POST", "im/user/sendMsgToMyselfs. action "," HTTP/1.1 ", NULL, NULL, 0, 0); if (NULL = hRqstHnd) {printf (" HttpOpenRequestA 3 failed. \ r \ n "); return;} H TtpAddRequestHeadersA (hRqstHnd, "Content-Type: application/x-www-form-urlencoded \ r \ n",-1, latency); bRqstRet = HttpSendRequestA (hRqstHnd, NULL, 0, (VOID *) pcMsgData, strlen (pcMsgData); if (TRUE! = BRqstRet) {printf ("HttpSendRequestA 3 failed \ r \ n"); return;} ZeroMemory (pucBuffer, FE_BUFFER_SIZE); dwBufferLen = FE_BUFFER_SIZE; dwIndex = 0; bQueryRet = HttpQueryInfoA (hRqstHnd, HTTP_QUERY_CONTENT_LENGTH, pucBuffer, & dwBufferLen, & dwIndex); if (TRUE = bQueryRet) {printf ("3: len = % s, % u \ r \ n ", pucBuffer, dwBufferLen); bReadRet = InternetReadFile (hRqstHnd, pucBuffer, FE_BUFFER_SIZE, & dwReadLe N); printf ("3 read ret = % u, len = % u \ r \ n", bReadRet, dwReadLen); printf ("-------- \ r \ n "); printf ("% s", pucBuffer); printf ("-------- \ r \ n");} else {printf ("3 no response body \ r \ n ");} printf ("All OK! \ R \ n "); InternetCloseHandle (hRqstHnd); InternetCloseHandle (hConnHnd); InternetCloseHandle (hSessHnd );}

  

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.