如何模拟浏览器的提交操作? 现在有一个应用,需要将表单数据加密后提交到服务器,我想在页面中嵌入一个控件,由控件将表单数据加密后提交到服务器,但不知道如何做提交操作。请问哪位兄弟知道这个问题的答案?或者有别的方法也可以。小弟先谢谢了! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /////////////////////////////////////////////////////////////////////////////////////////click submit button of IE window//If it works, it is written by masterz,otherwise I don't//know who writes it^_^///////////////////////////////////////////////////////////////////////////////////////void CGetIESrcDlg::NavigateToUrl(){// Import the following files in your stdafx.h// #import <mshtml.tlb> // Internet Explorer 5// #import <shdocvw.dll>// Refer to "Connect to Internet Explorer Instances, From your own Process. " in www.codeguru.comSHDocVw::IShellWindowsPtr m_spSHWinds;CoInitialize(NULL);if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK){IDispatchPtr spDisp;long nCount = m_spSHWinds->GetCount();for (long i = 0; i < nCount; i++){_variant_t va(i, VT_I4);spDisp = m_spSHWinds->Item(va);SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);if (spBrowser != NULL){IDispatchPtr spDisp;if(spBrowser->get_Document(&spDisp) == S_OK && spDisp!= 0 ){MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);MSHTML::IHTMLElementPtr spHtmlElement;if(spHtmlDocument==NULL)continue;spHtmlDocument->get_body(&spHtmlElement);if(spHtmlDocument==NULL)continue;HRESULT hr;MSHTML::IHTMLElementCollection* pColl=NULL;hr=spHtmlDocument->get_all(&pColl);if(pColl!=NULL&&SUCCEEDED(hr)){MSHTML::IHTMLElement* pElem=NULL;_variant_t index;index.vt=VT_I4;index.intVal=0;_variant_t name("Submit");IDispatchPtr disp;disp=pColl->item(name,index);if(disp==NULL)hr=E_FAIL;else{hr=disp->QueryInterface(&pElem);}if (SUCCEEDED(hr)&& pElem != NULL){//BSTR bstrhtml;pElem->get_outerHTML(&bstrhtml);CString str(bstrhtml);AfxMessageBox(str);pElem->click();pElem->Release();}pColl->Release();}}}}}else {AfxMessageBox("Shell Windows interface is not avilable");}CoUninitialize();} /////////////////////////////////////////////////////////////////////////////SDK post///////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "winsock.h"#pragma comment(lib,"ws2_32.lib")#define winsock_version 0x0101void main(){//I create C:\Inetpub\wwwroot\test\test.asp ,start the web service//start my program, the result is OK.//If it works,it is written by masterz,otherwise I don't know who write it. SOCKADDR_IN saServer;LPHOSTENT lphostent;WSADATA wsadata; SOCKET hsocket;int nRet;const char* host_name="127.0.0.1";char* req="POST /test/test.asp HTTP/1.0\r\n""From: local\r\n""User-Agent: post_test/1.0\r\n""Content-Type: application/x-www-form-urlencoded\r\n""Content-Length: 20\r\n\r\n""type=12345&name=aaaa";if(WSAStartup(winsock_version,&wsadata))printf("can't initial socket"); lphostent=gethostbyname(host_name); if(lphostent==NULL)printf("lphostent is null");hsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); saServer.sin_family = AF_INET;// Use def. now, need to handle general casesaServer.sin_port = htons(80); saServer.sin_addr = *((LPIN_ADDR)*lphostent->h_addr_list); nRet = connect(hsocket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));if (nRet == SOCKET_ERROR){printf("can't connect");closesocket(hsocket);return;}elseprintf("connected with %s\n",host_name);nRet = send(hsocket, req, strlen(req), 0);if (nRet == SOCKET_ERROR){printf("send() failed");closesocket(hsocket);}elseprintf("send() OK\n");char dest[1000]; nRet=1;while(nRet>0){nRet=recv(hsocket,(LPSTR)dest,sizeof(dest),0);if(nRet>0)dest[nRet]=0;elsedest[0]=0;printf("\nReceived bytes:%d\n",nRet);printf("Result:\n%s",dest);} } 用WinInet类可以狠方便的同HTTP服务器交互,包括你说的POST或者GET 谢谢各位的热心,我已经找到方法了。http://support.microsoft.com/kb/165298/en-us 边缘检测之后断边、伪边的处理问题 由于SetFocus(),使程序在win2008Ser下操作速度会变慢。 一个问题 关于输出字符串 请教COleDragDrop如何判断来源? 软件工程专业就是做数据库吗??? 不同模板的几个视图如何共享一个文档 我写的公开代码,欢迎批评指正。 mpc小问题。 请问谁看过《VC++编程高手》这本老书,希望出版的 怎样做WH_JOURNALPLAYBACK和WH_JOURNALRECORD钩子?(2) 怎样用vc实现bmp图像的另存? 第一次碰到这种代码,高手解答ConnectionPtr的问题。
//click submit button of IE window
//If it works, it is written by masterz,otherwise I don't
//know who writes it^_^
///////////////////////////////////////////////////////////////////////////////////////
void CGetIESrcDlg::NavigateToUrl()
{
// Import the following files in your stdafx.h
// #import <mshtml.tlb> // Internet Explorer 5
// #import <shdocvw.dll>
// Refer to "Connect to Internet Explorer Instances, From your own Process. " in www.codeguru.com
SHDocVw::IShellWindowsPtr m_spSHWinds;
CoInitialize(NULL);
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
{
IDispatchPtr spDisp;
long nCount = m_spSHWinds->GetCount();
for (long i = 0; i < nCount; i++)
{
_variant_t va(i, VT_I4);
spDisp = m_spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL)
{
IDispatchPtr spDisp;
if(spBrowser->get_Document(&spDisp) == S_OK && spDisp!= 0 )
{
MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
MSHTML::IHTMLElementPtr spHtmlElement;
if(spHtmlDocument==NULL)
continue;
spHtmlDocument->get_body(&spHtmlElement);
if(spHtmlDocument==NULL)
continue;
HRESULT hr;
MSHTML::IHTMLElementCollection* pColl=NULL;
hr=spHtmlDocument->get_all(&pColl);
if(pColl!=NULL&&SUCCEEDED(hr))
{
MSHTML::IHTMLElement* pElem=NULL;
_variant_t index;
index.vt=VT_I4;
index.intVal=0;
_variant_t name("Submit");
IDispatchPtr disp;
disp=pColl->item(name,index);
if(disp==NULL)
hr=E_FAIL;
else
{
hr=disp->QueryInterface(&pElem);
}
if (SUCCEEDED(hr)&& pElem != NULL)
{
//
BSTR bstrhtml;
pElem->get_outerHTML(&bstrhtml);
CString str(bstrhtml);
AfxMessageBox(str);
pElem->click();
pElem->Release();
}
pColl->Release();
}
}}
}}
else {
AfxMessageBox("Shell Windows interface is not avilable");
}
CoUninitialize();
}
//SDK post
///////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "winsock.h"
#pragma comment(lib,"ws2_32.lib")
#define winsock_version 0x0101
void main()
{
//I create C:\Inetpub\wwwroot\test\test.asp ,start the web service
//start my program, the result is OK.
//If it works,it is written by masterz,otherwise I don't know who write it.
SOCKADDR_IN saServer;
LPHOSTENT lphostent;
WSADATA wsadata;
SOCKET hsocket;
int nRet;
const char* host_name="127.0.0.1";
char* req="POST /test/test.asp HTTP/1.0\r\n"
"From: local\r\n"
"User-Agent: post_test/1.0\r\n"
"Content-Type: application/x-www-form-urlencoded\r\n"
"Content-Length: 20\r\n\r\n"
"type=12345&name=aaaa";
if(WSAStartup(winsock_version,&wsadata))
printf("can't initial socket");
lphostent=gethostbyname(host_name);
if(lphostent==NULL)
printf("lphostent is null");
hsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
saServer.sin_family = AF_INET;
// Use def. now, need to handle general case
saServer.sin_port = htons(80);
saServer.sin_addr = *((LPIN_ADDR)*lphostent->h_addr_list);
nRet = connect(hsocket, (LPSOCKADDR)&saServer, sizeof(SOCKADDR_IN));
if (nRet == SOCKET_ERROR)
{
printf("can't connect");
closesocket(hsocket);
return;
}
else
printf("connected with %s\n",host_name);
nRet = send(hsocket, req, strlen(req), 0);
if (nRet == SOCKET_ERROR)
{
printf("send() failed");
closesocket(hsocket);}
else
printf("send() OK\n");
char dest[1000];
nRet=1;
while(nRet>0)
{
nRet=recv(hsocket,(LPSTR)dest,sizeof(dest),0);
if(nRet>0)
dest[nRet]=0;
else
dest[0]=0;
printf("\nReceived bytes:%d\n",nRet);
printf("Result:\n%s",dest);
}
}
http://support.microsoft.com/kb/165298/en-us