没有合适的资源?快使用搜索试试~ 我知道了~
bool CTCSDlg::UpFileOfHttp(TCHAR* strSourceName,TCHAR* strDestName,TCHAR* _strFtpSite) { TCHAR* pName=new TCHAR[256]; wsprintf(pName,L"%s?filename=%s",m_strFtpSite,strDestName); AfxOutInfoToFile("===上传文件名:",strSourceName); AfxOutInfoToFile("===上传地址:",pName); ASSERT(m_strFtpSite != "" && strSourceName != ""); BOOL bResult = FALSE; DWORD dwType = 0; CString strServer; CString strObject;
资源推荐
资源详情
资源评论
bool CTCSDlg::UpFileOfHttp(TCHAR* strSourceName,TCHAR* strDestName,TCHAR* _strFtpSite)
{
TCHAR* pName=new TCHAR[256];
wsprintf(pName,L"%s?filename=%s",m_strFtpSite,strDestName);
AfxOutInfoToFile("===上传文件名:",strSourceName);
AfxOutInfoToFile("===上传地址:",pName);
ASSERT(m_strFtpSite != "" && strSourceName != "");
BOOL bResult = FALSE;
DWORD dwType = 0;
CString strServer;
CString strObject;
INTERNET_PORT wPort = 80;
DWORD dwFileLength = 0;
char * pFileBuff = NULL;
CHttpConnection * pHC = NULL;
CHttpFile * pHF = NULL;
CInternetSession cis;
bResult = AfxParseURL(pName, dwType, strServer, strObject, wPort);
AfxOutInfoToFile(L"===解析的服务器:",strServer.GetBuffer(strServer.GetLength()));
AfxOutInfoToFile(L"===解析的地址:",strObject.GetBuffer(strObject.GetLength()));
//AfxOutInfoToFile("===解析的地址:",m_strFtpSite);
if(!bResult)
return false;
CFile file;
try
{
if(!file.Open(strSourceName, CFile::shareDenyNone | CFile::modeRead))
{
TCHAR* pName=new TCHAR[256];
wsprintf(pName,L"%s?filename=%s",m_strFtpSite,strDestName);
AfxOutInfoToFile("===上传文件名:",strSourceName);
AfxOutInfoToFile("===上传地址:",pName);
ASSERT(m_strFtpSite != "" && strSourceName != "");
BOOL bResult = FALSE;
DWORD dwType = 0;
CString strServer;
CString strObject;
INTERNET_PORT wPort = 80;
DWORD dwFileLength = 0;
char * pFileBuff = NULL;
CHttpConnection * pHC = NULL;
CHttpFile * pHF = NULL;
CInternetSession cis;
bResult = AfxParseURL(pName, dwType, strServer, strObject, wPort);
AfxOutInfoToFile(L"===解析的服务器:",strServer.GetBuffer(strServer.GetLength()));
AfxOutInfoToFile(L"===解析的地址:",strObject.GetBuffer(strObject.GetLength()));
//AfxOutInfoToFile("===解析的地址:",m_strFtpSite);
if(!bResult)
return false;
CFile file;
try
{
if(!file.Open(strSourceName, CFile::shareDenyNone | CFile::modeRead))
return false;
dwFileLength = file.GetLength();
if(dwFileLength <= 0)
return false;
pFileBuff = new char[dwFileLength];
memset(pFileBuff, 0, sizeof(char) * dwFileLength);
file.Read(pFileBuff, dwFileLength);
const int nTimeOut = 5000;
cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, nTimeOut); //联接超时设置
cis.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 1); //重试1次
pHC = cis.GetHttpConnection(strServer, wPort); //取得一个Http联接
pHF = pHC->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject);
if(!pHF->SendRequest(NULL, 0, pFileBuff, dwFileLength))
{
delete[]pFileBuff;
pFileBuff = NULL;
pHF->Close();
pHC->Close();
cis.Close();
AfxOutInfoToFile(L"上传中,SendRequest error\n");
return FALSE;
}
CString szError=L"0";
char szBuff[1024];
UINT nRead;
while (nRead = pHF->Read(szBuff,1023))
dwFileLength = file.GetLength();
if(dwFileLength <= 0)
return false;
pFileBuff = new char[dwFileLength];
memset(pFileBuff, 0, sizeof(char) * dwFileLength);
file.Read(pFileBuff, dwFileLength);
const int nTimeOut = 5000;
cis.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, nTimeOut); //联接超时设置
cis.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 1); //重试1次
pHC = cis.GetHttpConnection(strServer, wPort); //取得一个Http联接
pHF = pHC->OpenRequest(CHttpConnection::HTTP_VERB_POST, strObject);
if(!pHF->SendRequest(NULL, 0, pFileBuff, dwFileLength))
{
delete[]pFileBuff;
pFileBuff = NULL;
pHF->Close();
pHC->Close();
cis.Close();
AfxOutInfoToFile(L"上传中,SendRequest error\n");
return FALSE;
}
CString szError=L"0";
char szBuff[1024];
UINT nRead;
while (nRead = pHF->Read(szBuff,1023))
剩余10页未读,继续阅读
资源评论
fanhongjun2004
- 粉丝: 6
- 资源: 94
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功