C++模拟Http/Https POST登录web站点(三)
break;
}
bRet = TRUE;
} while (FALSE);
return bRet;
}
BOOL HttpsClient::InitializeSslContext()
{
//!SSL通信初始化
BOOL bRet = FALSE;
do
{
sslMethod = SSLv23_client_method();
if(NULL == sslMethod)
{
break;
}
sslCtx = SSL_CTX_new(sslMethod);
if (NULL == sslCtx)
{
break;
}
ssl = SSL_new(sslCtx);
if (NULL == ssl)
{
break;
}
bRet = TRUE;
} while (FALSE);
return bRet;
}
BOOL HttpsClient::SslConnect()
{
//!SSL绑定原生socket,并连接服务器
BOOL bRet = FALSE;
do
{
SSL_set_fd(ssl, socketClient);
int nRet = SSL_connect(ssl);
if (-1 == nRet)
{
break;
}
bRet = TRUE;
} while (FALSE);
return bRet;
}
BOOL HttpsClient::SslGetCipherAndCertification()
{
BOOL bRet = FALSE;
do
{
cstrSslCipher = SSL_get_cipher(ssl);
serverCertification = SSL_get_certificate(ssl);
if (NULL == serverCertification)
{
break;
}
cstrSslSubject = X509_NAME_oneline(X509_get_subject_name(serverCertification), 0, 0);
cstrSslIssuer = X509_NAME_oneline(X509_get_issuer_name(serverCertification), 0, 0);
X509_free(serverCertification);
bRet = TRUE;
} while (FALSE);
return bRet;
}
BOOL HttpsClient::SendLoginPostData()
{
CString cstrSendData;
//CString cstrSendParam = redirect=&username=+cstrUserName+&password=+cstrPassWord+&auto_login=checked&submit=%E7%99%BB%E5%BD%95;
CString cstrSendParam = user=+cstrUserName+&_json=true&pwd=+cstrPassWord+&callback=http%3A%2F%2Forder.mi.com%2Flogin%2Fcallback%3Ffollowup%3Dhttp%253A%252F%252Fwww.mi.com%252F%26sign%3DNWU4MzRmNjBhZmU4MDRmNmZkYzVjMTZhMGVlMGFmMTllMGY0ZTNhZQ%2C%2C&sid=mi_eshop&qs=%253Fcallback%253Dhttp%25253A%25252F%25252Forder.mi.com%25252Flogin%25252Fcallback%25253Ffollowup%25253Dhttp%2525253A%2525252F%2525252Fwww.mi.com%2525252F%252526sign%25253DNWU4MzRmNjBhZmU4MDRmNmZkYzVjMTZhMGVlMGFmMTllMGY0ZTNhZQ%25252C%25252C%2526sid%253Dmi_eshop&hidden=&_sign=%2Bw73Dr7cAfRlMfOR6fW%2BF0QG4jE%3D&serviceParam=%7B%22checkSafePhone%22%3Afalse%7D&captCode=;
BOOL bRet = FALSE;
CString cstrSendParamLen;
cstrSendParamLen.Format(%d, cstrSendParam.GetLength());
cstrSendData = POST https://account.xiaomi.com/pass/serviceLoginAuth2 HTTP/1.1
;
cstrSendData += Host: account.xiaomi.com
;
cstrSendData += User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
;
cstrSendData += Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
;
cstrSendData += Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
;
cstrSendData += Accept-Encoding: gzip, deflate
;
cstrSendData += DNT: 1
;
cstrSendData += Content-Type: application/x-www-form-urlencoded; charset=UTF-8
;
cstrSendData += Referer: https://account.xiaomi.com/pass/serviceLogin?callback=http%3A%2F%2Forder.mi.com%2Flogin%2Fcallback%3Ffollowup%3Dhttp%253A%252F%252Fwww.mi.com%252Findex.html%26sign%3DNDRhYjQwYmNlZTg2ZGJhZjI0MTJjY2ZiMTNiZWExODMwYjkwNzg2ZQ%2C%2C&sid=mi_eshop
;
cstrSendData += Content-Length: + cstrSendParamLen +
;
cstrSendData += Connection: keep-alive
;
cstrSendData +=
| 评论 |
|
|