有接触过这方面问题的人吗?
解决方案 »
- 请大家帮忙!VC6+BCG开发的代码怎样移植到Visual Studio 2008下?
- FLASH 做界面多好啊,简单省事,效果一流
- 在我自己派生一个CTreeCtrl类中添加左键双击消息,然后用classWizard将该类与控件关联在一起, 可调试时发现不能进入该消息里?
- 请教
- 关于代码AfxMessageBox(_T("Couldn't create the file!")),请教!
- 突然纳闷了,消息循环不是一直循环吗?为什么cpu的占用又没有呢?
- 求哈答案 急用啊 谢谢大家
- 请教如何使用VC在客户端连接服务器端的ORACLE的表?谢谢!
- 如何在文件的中部用 ostream 插入或删除内容!
- 救命啊!我的一个文件无端不见了!
- 如何设置对话框启动时文本框自动获得输入焦点
- 如何才能得到SDI 的主窗口的CWnd* 指针
1.可以在 ActiveX中使用Socket 与相应的服务端通讯,由服务端负责保存数据到数据库中。
2.可以使用DCOM。
3.使用 COM+
4.使用Web Service
CHttpConnection* pServer=NULL;
CHttpFile* pFile=NULL;
CString strServerName=m_ServerName;
INTERNET_PORT nPort=(INTERNET_PORT)atoi(m_ServerPort);
CString strURL=m_DesignFile;
try
{
pServer=m_Session.GetHttpConnection(strServerName,nPort);
pFile=pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,strURL,NULL,1,NULL,NULL,INTERNET_FLAG_EXISTING_CONNECT);
CString strBoundary="-----------------------------7d33a816d302b6";//分界线视CGI程序做响应改动.
pFile->AddRequestHeaders("Content-Type: multipart/form-data, boundary="+strBoundary);
pFile->AddRequestHeaders("Accept: **");
char* pBuf=new char[1024*1000];
//构造表单开始
FieldStruct* pFieldStruct=new FieldStruct;
POSITION CurrentPosition;
for(int iIndex=0;iIndex<m_FieldData.GetCount();iIndex++)
{
CurrentPosition=m_FieldData.FindIndex(iIndex);
pFieldStruct=(FieldStruct*)m_FieldData.GetAt(CurrentPosition); strcat(pBuf,(LPTSTR)(LPCTSTR)strBoundary); strcat(pBuf,"Content-Disposition: form-data;name=\"");
strcat(pBuf,(LPTSTR)(LPCTSTR)pFieldStruct->m_FieldName);
strcat(pBuf,"\"\r\n\r\n");
strcat(pBuf,(LPTSTR)(LPCTSTR)pFieldStruct->m_FieldValue);
strcat(pBuf,"\r\n");
strcat(pBuf,(LPTSTR)(LPCTSTR)strBoundary);
}
//构造表单结束
//
CStdioFile m_File;
BYTE pFileBuf[1024];
CString strBuf;
DWORD dwRead;
strcat(pBuf,"Content-Disposition: form-data;name=\"FieldName\"\r\nfilename=\"FileName\"\r\n");
if(m_File.Open(strTempDocPath,CFile::modeRead|CFile::typeBinary))
{
do
{
dwRead=m_File.Read(pFileBuf,1024);
for(int kIndex=0;kIndex<(int)dwRead;kIndex++)
{
char strChar=*(char*)(pFileBuf+kIndex);
if(strChar=='\0')
{
strBuf.Append("DigitalTitan",12);
}
else
{
strBuf.AppendChar(strChar);
}
//int iLastPosition=strlen(pBuf);
//pBuf[iLastPosition]=strChar;
//pBuf[iLastPosition+1]=0;
}
}
while(dwRead>0);
m_File.Close();
}
strcat(pBuf,(LPTSTR)(LPCTSTR)strBuf);
strcat(pBuf,"\r\n");
strcat(pBuf,(LPTSTR)(LPCTSTR)strBoundary);
strcat(pBuf,"--");
pFile->SendRequest(NULL,0,(LPVOID)pBuf,strlen(pBuf));
pFile->Close();
pServer->Close();
//AfxMessageBox("UpLoad...",MB_ICONINFORMATION);
}
catch(CInternetException * e)
{
AfxMessageBox("...",MB_ICONINFORMATION);
};
delete pFile;
delete pServer;
m_Session.Close();
你的程序应该是利用了HTTP协议吧,基本原理是不是通过构造一个类似HTML中的表单来把数据发送到服务器上去? 谢谢,很不错的做法,简单又实用,但假如我要利用Activex和HTTP协议来向服务器发送二进制文件呢?怎么用Activex利用服务器的文件上传功能?