描述:
如题。
我用CAtlNavigateData类,不能实现。
谁有这方面的经验?请指教。谢谢!
解决方案1:
以下程序在VC++.net下MFC环境调试通过[WIN2000Server]
CInternetSession m_Session("DigitalTitan");
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();
QQ:81051043