CInternetSession

网络编程,CInternetSession,OpenUrl,CStdion,exe 请问用CInternetSession.OpenUrl函数和CStdion类从网站上下载一个exe文件的方法
作者:不详  来源:本站整理  发布时间:2007-1-22 8:57:56  发布人:Admin
 

减小字体 增大字体

问题 于 2006-09-15 00:18
如题:
我的代码如下:
char szbuff[1024] ;
szbuff[1023] = '/0' ;
static char fileName[] = "c://1. exe" ;
CFile file(fileName , CFile::modeCreate | CFile::modeWrite) ;

CInternetSession session ;
CStdioFile * pFile = NULL ;

try
{

pFile = session.OpenURL(szUrl) ;

while (pFile->Read(szbuff, 1023) != 0)
{
file.Write(szbuff, 1024) ;
}
}
catch(CInternetException * e)
{
AfxMessageBox("error!") ;
e->Delete();

}

file.Cl ose() ;
if(pFile)
{
delete pFile ;
}
session.Cl ose() ;

下载下来后,1. exe文件中为一个页面无法打开的htm页面,请教正确的下载方法。
<---->
响应者 1:
刚才看了下msdn,原来如此。
To use connection-specific (that is, protocol-specific) functions, such as writing to a file, you must open a session, then open a particular kind of connection, then use that connection to open a file in the desired mode. See CInternetConnection for more information about connection-specific functions.

<---->
响应者 2:
楼主有使用到 断点续传吗?小弟正在研究这个,如果有的话,希望不吝赐教
你所要下载的文件是ftp服务器上还是http服务器上呀?
我看了,如果你这个程序不改成 断点续传的说,基本上是通用的,但要是改成 断点续传的话,就不行了,如果你有更好的解决方法,希望能贴出来,小弟学习一下。
<---->
响应者 3:
CInternetSession mySession;
CHttpFile* myHttpFile;
CStdioFile* csf=new CStdioFile;
try
{

myHttpFile=(CHttpFile*)mySession.OpenURL(m_thistruct->fileurl);
CString queryinfo;
myHttpFile->QueryInfo(HTTP_QUERY_STATUS_CODE,queryinfo);
if(queryinfo=="200")
{
myHttpFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH,queryinfo);
m_thistruct->m_Size=(float)atof(queryinfo);

char buf[4096];

int n;


if(csf->Open(url,CFile::modeRead|CFile::modeWrite | CFile::typeBinary | CFile::shareDenyWrite))
{
myHttpFile->Seek(csf->GetLength(),CHttpFile::begin);
m_thistruct->m_DownSize=(float)csf->SeekToEnd();
while((n=myHttpFile->Read(buf,sizeof(buf)))>0)//
{
csf->Write(buf,n);
}
}
else
{
if(csf->Open(m_thistruct->clentfilepath,CFile::modeCreate|CFile::modeWrite | CFile::typeBinary | CFile::shareDenyWrite))
{
while((n=myHttpFile->Read(buf,sizeof(buf)))>0)
{
csf->Write(buf,n);
}
}
}

}

}catch(CException *e)
{
e->Delete();

}
if(csf)
{
csf->Cl ose();
}
delete csf;
if(myHttpFile)
{
myHttpFile->Cl ose();
}
delete myHttpFile;
mySession.Cl ose();
<----><---->
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值