16,472
社区成员
发帖
与我相关
我的任务
分享
HINTERNET hInternet,hConnect,hRequest;
BOOL bRet;
CString strResponse;
char* strPostData;
hInternet = InternetOpen(L"User-Agent",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
LPCWSTR lpHostName = L"www.kaixin001.com";
USHORT sPort = 80;
if(!hInternet)
goto Ret0;
hConnect = InternetConnect(hInternet, lpHostName, sPort, NULL, L"HTTP/1.1",INTERNET_SERVICE_HTTP,0,0);
if(!hConnect)
goto Ret0;
hRequest = HttpOpenRequest(hConnect, L"POST", L"login/login.php", L"HTTP/1.1", NULL,NULL,INTERNET_FLAG_RELOAD, 0);
if(!hRequest)
goto Ret0;
bRet = HttpAddRequestHeaders(hRequest, L"Content-Type: application/x-www-form-urlencoded", -1,HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
if(!bRet)
goto Ret0;
strPostData = "email=healer_kx@163.com&password=*********&url=/home/";
bRet = HttpSendRequest(hRequest, NULL, 0, (LPVOID)strPostData, strlen(strPostData));
BOOL CDlgD4::RegTaobao(CString strEmail, CString strUserName, CString strPassword)
{
CString strInputName;
CString strInputPW;
{
strInputName = _T("Email");
strInputPW = _T("Passwd");
}
BSTR bsPW = strPassword.AllocSysString();
BSTR bsUser = strUserName.AllocSysString();
BSTR bsEamil = strEmail.AllocSysString();
map<CString, BSTR> mapTaobaoInputInfo;
mapTaobaoInputInfo[TAOBAO_HTML_INPUT_EMAIL] = bsEamil;
mapTaobaoInputInfo[TAOBAO_HTML_INPUT_USERNAME] = bsUser;
mapTaobaoInputInfo[TAOBAO_HTML_INPUT_JPASSWORD] = bsPW;
mapTaobaoInputInfo[TAOBAO_HTML_INPUT_JREPASSWORD] = bsPW;
//m_regUrl.Navigate("http://member1.taobao.com/member/register.jhtml", NULL, NULL, NULL, NULL);
HRESULT hr;
COleVariant vaURL("http://member1.taobao.com/member/register.jhtml");
hr = CoCreateInstance (CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER,
IID_IWebBrowser2, (LPVOID *)&m_pBrowser);
VARIANT_BOOL pBool=TRUE;
m_pBrowser->put_Visible(pBool) ;
VARIANT vNull;
VariantInit(&vNull);
vNull.vt = VT_BSTR;
vNull.bstrVal = NULL;
m_pBrowser->Navigate2(vaURL,&vNull,&vNull,&vNull,&vNull) ;
READYSTATE emReadState;
m_pBrowser->get_ReadyState(&emReadState);
while (READYSTATE_COMPLETE != emReadState)
{
m_pBrowser->get_ReadyState(&emReadState);
}
IDispatch* pDispDocument;
hr = m_pBrowser->get_Document(&pDispDocument);
IHTMLDocument2* pHTMLDocument2;
hr = pDispDocument->QueryInterface( IID_IHTMLDocument2,(void**)&pHTMLDocument2 );
if (hr == S_OK)
{
IHTMLElementCollection* pColl = NULL;
hr = pHTMLDocument2->get_all(&pColl);
if (hr == S_OK && pColl != NULL)
{
LONG lNumElem;
hr = pColl->get_length( &lNumElem );
if ( hr == S_OK )
{
for (int i = 0 ; i < lNumElem ; ++i)
{
VARIANT varIndex;
varIndex.vt = VT_UINT;
varIndex.lVal = i;
VARIANT var2;
VariantInit( &var2 );
IDispatch* pDispItem;
hr = pColl->item( varIndex, var2, &pDispItem );
if ( hr == S_OK )
{
IHTMLElement* pElem;
hr = pDispItem->QueryInterface(IID_IHTMLElement,(void **)&pElem);
if ( hr == S_OK )
{
BSTR bstr;
hr = pElem->get_tagName(&bstr);
CString strTag;
strTag = bstr;
IHTMLInputTextElement* pUserInput;
hr = pDispItem->QueryInterface(IID_IHTMLInputTextElement, (void **)&pUserInput );
if ( hr == S_OK )
{
pUserInput->get_name(&bstr);
CString strName;
strName=bstr;
if( mapTaobaoInputInfo.end() != mapTaobaoInputInfo.find(strName) )
{
pUserInput->put_value(mapTaobaoInputInfo[strName]);
}
pUserInput->Release();
}
else
{
{
IHTMLInputButtonElement* pUserButton;
hr = pDispItem->QueryInterface(
IID_IHTMLInputButtonElement,
(void **)&pUserButton );
if (hr == S_OK)
{
BSTR bsBtName;
pUserButton->get_type(&bstr);
pUserButton->get_value(&bsBtName);
CString strTypeName, strBtName;
strTypeName = CString(bstr);
strBtName = CString(bsBtName);
if (hr == S_OK && strTypeName == _T("submit") && strBtName == TAOBAO_HTML_BTN_SUBMIT_NAME)
{
IHTMLFormElement* pForm;
hr=pUserButton->get_form(&pForm);
if ( hr == S_OK )
{
hr = pForm->submit();
pForm->Release();
break;
}
pUserButton->Release();
}
}
}
}
pElem->Release();
}
pDispItem->Release();
}
}
}
pColl->Release();
}
pHTMLDocument2->Release();
pDispDocument->Release();
}
m_pBrowser->Release();
return TRUE;
}