标签:
注:
1、下文中所有HTTP请求所指的Host都是f.10086.cn
2、目前只有中国移动用户可以使用
1、打开登录页面:GET /huc/user/space/login.do?m=submit&fr=space,获取两个cookie值:JSESSIONID和UUID
2、登录:POST /huc/user/space/login.do,数据为手机号码和密码:mobilenum=your_phone_number&password=your_fetioon_password&m=submit&backurl=http%3A%2F%2Ff.10086.cn%2F&fr=space,获取cookie值:Set-Cookie: cell_cookie,注意:登录时,需要携带header:Content-Type: application/x-www-form-urlencoded,否则会触发验证码检查
2.1、上述步骤2会重定向到其他路径:Location: http://f.10086.cn/?nuc_id=5cb9e9eca65e2bc2875a6fe55869daa1,4e8cbe602e50b189ddc33e51de704474,e017a7e72b081563f1fbf1263d2fd8f8,1
2.2、http://f.10086.cn/?nuc_id=5cb9e9eca65e2bc2875a6fe55869daa1,4e8cbe602e50b189ddc33e51de704474,e017a7e72b081563f1fbf1263d2fd8f8,1<----这个会继续重定向到Location: http://f.10086.cn/wap2.jsp,同时会重置cookie值:JSESSIONID。wap2.jsp是一个新闻综合网页。
3、发送消息:POST /im/user/sendMsgToMyselfs.action HTTP/1.1,数据:msg=A hello word short message
3.1、上述步骤可能会被重定向到Location: http://f.10086.cn/im/login/cklogin.action?t=1420875966727,此时可以重新POST /im/user/sendMsgToMyselfs.action HTTP/1.1,即可发送成功。
一下是使用MFC Wininet实现的Demo,在本文章发布时,还是可以发送短信的
另外,代码没有经过锤炼,请不要在意内存泄露等bug。。。
#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;
//使用fiddler代理
hSessHnd = InternetOpenA("FetionMsg", INTERNET_OPEN_TYPE_PROXY, "http=http://127.0.0.1:8888", NULL, 0);
//直接登录
//hSessHnd = InternetOpenA("FetionMsg", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
if (NULL == hSessHnd)
{
printf("InternetOpenA failed\r\n");
return;
}
hConnHnd = InternetConnectA(hSessHnd, "f.10086.cn", INTERNET_DEFAULT_HTTP_PORT, 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, FE_BUFFER_SIZE);
dwBufferLen = FE_BUFFER_SIZE;
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");
return;
}
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, &dwReadLen);
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;
}
const 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, &dwReadLen);
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;
}
HttpAddRequestHeadersA(hRqstHnd, "Content-Type: application/x-www-form-urlencoded\r\n", -1, HTTP_ADDREQ_FLAG_ADD);
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, &dwReadLen);
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);
}
标签:
原文地址:http://www.cnblogs.com/shijianyujingshen/p/4219932.html