以下是本人的文件下载代码
如果strURL格式为 http://www.showqq.com/download/Soft_down.asp?SoftID=821
则无法正确下载文件BOOL DownFile(CString strURL,CString strSave)
{
CInternetSession lInternetSession(NULL,1,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);

CHttpFile* pHttpFile=NULL;
try
{
DWORD dwRet;
pHttpFile = (CHttpFile*)lInternetSession.OpenURL(strURL);
pHttpFile->QueryInfoStatusCode(dwRet);
}
catch(CInternetException* e)
{
char szCause[255];
e->GetErrorMessage(szCause, 255);
AfxMessageBox(szCause);
e->Delete();
pHttpFile=NULL;
return FALSE;
}


if(pHttpFile)
{
CStdioFile lStdioFile;
lStdioFile.Open(strSave,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);

char chrBuffer[2048];
DWORD dwBytesRead;
while((dwBytesRead=pHttpFile->Read(chrBuffer,2048))>0)
{
lStdioFile.Write(chrBuffer,dwBytesRead);
}

lStdioFile.Close();
pHttpFile->Close();
delete pHttpFile;
pHttpFile=NULL;
}
}

解决方案 »

  1.   

    这个好象没有什么办法, 只有在Web上直接打开才可以把.
    我以前也编过这种程序,用asp编的都是下不下来的, 因为你不知道文件存储所在位置的真正URL
      

  2.   

    CInternetSession session;
    CHttpConnection* pServer = NULL;
    CHttpFile* pFile = NULL;
    try
    {

    if(!OnInitSession(session))
    {
    return FALSE;
    }
    if (!AfxParseURL( (LPCTSTR)sURL, dwServiceType, strServerName, strObject, nPort) ||
    dwServiceType != INTERNET_SERVICE_HTTP)
    {
    str_Error = "非法的URL";
    return FALSE;
    }
    pServer = session.GetHttpConnection(strServerName, nPort);
    if(pServer==NULL)
    {
    str_Error = "无法与服务器建立连接";
    return FALSE;
    }
    pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags); if(pFile==NULL)
    {
    str_Error = "无法与服务器建立连接";
    return FALSE;
    }
    //////////////////////////////////////////////////////////////////////////
            try
       {
    if(!pFile->AddRequestHeaders(szHeaders)|| !pFile->SendRequest())
    {
                str_Error ="网络错误-无法发送请求报头";
    return FALSE;
    }
       }
       catch (CInternetException* ex) 
       {
       fileContent.Empty();
       str_Error="无法发送http报头,可能网络状况有问题";
       ex->Delete();
       return FALSE;
       }
       //////////////////////////////////////////////////////////////////////////
       
    if(!pFile->QueryInfoStatusCode(dwRetcode))
    {
    str_Error ="网络错误-无法查询反馈代码";
    return FALSE;
    } if(dwRetcode>=200&&dwRetcode<300)
    {     

    if(!OnQuerLastMendTime(m_site_LSTime,news_Time,pFile))
    {
                       return TRUE;
    }
    else
    {
    news_Time = odNowtime;
    return OnGetData(session,pServer,pFile,fileContent);
    }
    }
            else
    {
    //重新定向
    if( dwRetcode >= 300 && dwRetcode <= 306 )
    {

    pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation); int nPlace = strNewLocation.Find(_T("Location: "));
    if (nPlace == -1)
    {
    str_Error ="Error: Site redirects with no new location";
    if (pFile != NULL)
    delete pFile;
    if (pServer != NULL)
    delete pServer;
    session.Close();
    return FALSE;
    } strNewLocation = strNewLocation.Mid(nPlace + 10);
    nPlace = strNewLocation.Find('\n');
    if (nPlace > 0)
    {
    strNewLocation = strNewLocation.Left(nPlace);
    }
       
    if(strNewLocation.Find("http://",0)<0)
    {
    sURL = OnConversionURL(sURL,strNewLocation);
    }
    else
    {
    sURL = strNewLocation;
    }
    fileContent.Empty();
    pFile->Close();
    delete pFile;
    pServer->Close();
    delete pServer;
      

  3.   

    用 pFile->QueryInfoStatusCode(dwRetcode) 查询反馈的状态码 300-306为重新定向
    pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation); int nPlace = strNewLocation.Find(_T("Location: "));
    if (nPlace == -1)
    {
    str_Error ="Error: Site redirects with no new location";
    if (pFile != NULL)
    delete pFile;
    if (pServer != NULL)
    delete pServer;
    session.Close();
    return FALSE;
    } strNewLocation = strNewLocation.Mid(nPlace + 10);
    nPlace = strNewLocation.Find('\n');
    if (nPlace > 0)
    {
    strNewLocation = strNewLocation.Left(nPlace);
    }
      

  4.   

    楼上的兄弟,你的代码我看了也试了不行啊,能不能给个详细些的代码
    szHeaders = ?
    dwHttpRequestFlags=?
      

  5.   

    是可以转化为有效URL的,就是不知道方法,不然windows默认的下载程序和网际快车是如何完成
      

  6.   

    asp 传给客户端浏览器的不是asp文件,还是html.但该html是被解释过的。
                                       我不知道自己用词是否正确,就是这个意思了
      

  7.   

    to ToWeightAnchor(ddd):
    对头,ASP是浏览器负责解释的,显示到客户端就成了htm,你用另存为b保存的是htm格式的。
      

  8.   

    <script language=JavaScript>window.open('http://www.qqpm.com/f/?showqqdown');window.focus();</script><meta HTTP-EQUIV=REFRESH CONTENT='0; URL=qqdown_352.htm'>正在进入下载页面... 如不能自动跳转,<a href=qqdown_352.htm>请点击此处</a>这是下载下来的文件
      

  9.   

    我看了一下网际快车,发现它在下载此类文件时显示的是:
    网址:http://www.showqq.com/download/Soft_down.asp?SoftID=821
    引用:http://www.showqq.com/download/qqdown_352.htm
    重命名:Soft_down.asp不知是否是先将Soft_down.asp文件下载下来,再分析此文件
      

  10.   

    查找response.redirect,这个是重定向文件得if current page is http://127.0.0.1/homepage/a.asp
    then 
    0)currentpage:http://127.0.0.1/homepage/a.asp1)Response.Redirect "homepage.asp"
    means
    http://127.0.0.1/homepage/homepage.asp2)Response.Redirect "anotherpath/homepage.asp"
    means
    http://127.0.0.1/homepage/anotherpath/homepage.asp3)Response.Redirect "anotherpath/download.zip"
    the same as 2)4)Response.Redirect "../homepage.asp"
    means
    http://127.0.0.1/homepage.asp../ means 上一级目录
      

  11.   

    还要识别<a href=..............刚才我用忘记快车,下载了以后是解释过得ASP,已经不是ASP了应该调用一些组件了进行处理了
      

  12.   

    不好意思,点错了前面我已经说过了嘛
    不可能下到的
    ASP是根据你的请求来生成给你看的页面
    给你看的页面就是HTML形式的如果那么容易就下到了
    那网站就没有一点安全性可言了包括JSP和其他的语言都是这个原理的
      

  13.   

    看看flashget的下载过程
    Sat Nov 06 19:14:05 2004 GET /download/Soft_down.asp?SoftID=821 HTTP/1.1
    Sat Nov 06 19:14:05 2004 Host: www.showqq.com
    Sat Nov 06 19:14:05 2004 Accept: */*
    Sat Nov 06 19:14:05 2004 Referer: http://www.showqq.com/download/qqdown_352.htm
    Sat Nov 06 19:14:05 2004 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
    Sat Nov 06 19:14:05 2004 Pragma: no-cache
    Sat Nov 06 19:14:05 2004 Cache-Control: no-cache
    Sat Nov 06 19:14:05 2004 Connection: close
    Sat Nov 06 19:14:05 2004 HTTP/1.1 302 Object moved
    Sat Nov 06 19:14:05 2004 Server: Microsoft-IIS/5.0
    Sat Nov 06 19:14:05 2004 Date: Sat, 06 Nov 2004 11:14:44 GMT
    Sat Nov 06 19:14:05 2004 Connection: close
    Sat Nov 06 19:14:05 2004 Location: http://dl.showqq.com/showqqdl/CoralQQ_showqq.com.rar
    Sat Nov 06 19:14:05 2004 Content-Length: 121
    Sat Nov 06 19:14:05 2004 Content-Type: text/html
    Sat Nov 06 19:14:05 2004 Set-Cookie: ASPSESSIONIDSQBATCAS=PLLBGKJBIGGBIKBNKJBEDDJO; path=/
    Sat Nov 06 19:14:05 2004 Cache-control: private
    Sat Nov 06 19:14:05 2004 重定向到 http://dl.showqq.com/showqqdl/CoralQQ_showqq.com.rar
    Sat Nov 06 19:14:05 2004 正在连接 dl.showqq.com:80
    Sat Nov 06 19:14:05 2004 正在连接 dl.showqq.com [IP=61.152.251.66:80]
    Sat Nov 06 19:14:05 2004 已连接.
    Sat Nov 06 19:14:05 2004 GET /showqqdl/CoralQQ_showqq.com.rar HTTP/1.1
    Sat Nov 06 19:14:05 2004 Host: dl.showqq.com
    Sat Nov 06 19:14:05 2004 Accept: */*
    Sat Nov 06 19:14:05 2004 Referer: http://www.showqq.com/download/qqdown_352.htm
    Sat Nov 06 19:14:05 2004 Cookie: ASPSESSIONIDSQBATCAS=PLLBGKJBIGGBIKBNKJBEDDJO
    Sat Nov 06 19:14:05 2004 User-Agent: Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)
    Sat Nov 06 19:14:05 2004 Pragma: no-cache
    Sat Nov 06 19:14:05 2004 Cache-Control: no-cache
    Sat Nov 06 19:14:05 2004 Connection: close
    Sat Nov 06 19:14:05 2004 HTTP/1.1 200 OK
    应该先查看返回信息,如果是302就表示对象重定向,查看服务器返回的
    Location: 信息,最终位置就在里面
      

  14.   

    by 114sky用 pFile->QueryInfoStatusCode(dwRetcode) 查询反馈的状态码 300-306为重新定向
    pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation); int nPlace = strNewLocation.Find(_T("Location: "));
    if (nPlace == -1)
    {
    str_Error ="Error: Site redirects with no new location";
    if (pFile != NULL)
    delete pFile;
    if (pServer != NULL)
    delete pServer;
    session.Close();
    return FALSE;
    } strNewLocation = strNewLocation.Mid(nPlace + 10);
    nPlace = strNewLocation.Find('\n');
    if (nPlace > 0)
    {
    strNewLocation = strNewLocation.Left(nPlace);
    }
      

  15.   

    static BOOL Down(CString strURL, CString strSave)
    {
    CInternetSession session(NULL,1,INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
    CHttpConnection* pServer = NULL;
    CHttpFile* pFile = NULL; CString strServer;
    CString strObject;
    DWORD dwServiceType;
    INTERNET_PORT nServerPort;
    if(!AfxParseURL(strURL, dwServiceType, strServer, strObject, nServerPort))
    {
    TRACE("非法的URL");
    return FALSE;
    }

    if(dwServiceType != INTERNET_SERVICE_HTTP) 
    {
    TRACE("非法的URL");
    return FALSE;
    }

    pServer = session.GetHttpConnection(strServer, nServerPort);
    if(pServer==NULL)
    {
    TRACE("无法与服务器建立连接");
    return FALSE;
    }

    DWORD dwHttpRequestFlags = INTERNET_FLAG_FROM_CACHE;
    pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET, strObject, NULL, 1, NULL, NULL, dwHttpRequestFlags);
    if(pFile==NULL)
    {
    TRACE("无法与服务器建立连接");
    return FALSE;
    }

    try
    {
    CHAR szHeaders[] = "Accept: */*\r\n\r\n";
    if(!pFile->AddRequestHeaders(szHeaders)|| !pFile->SendRequest())
    {
    TRACE("网络错误-无法发送请求报头");
    return FALSE;
    }
    }
    catch (CInternetException* ex) 
    {
    TRACE("无法发送http报头,可能网络状况有问题");
    ex->Delete();
    return FALSE;
    }

    //////////////////////////////////////////////////////////////////////////
    DWORD dwRetcode = 0;
    if(!pFile->QueryInfoStatusCode(dwRetcode))
    {
    TRACE("网络错误-无法查询反馈代码");
    return FALSE;
    }

    if(dwRetcode >=200 && dwRetcode < 300)
    {
    TRACE("正常文件");
    }
    else if(dwRetcode >= 300 && dwRetcode <= 306)
    {
    CString strNewLocation;
    pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);
    int nPlace = strNewLocation.Find(_T("Location: "));
    if (nPlace == -1)
    {
    TRACE("Error: Site redirects with no new location");
    if (pFile != NULL)
    delete pFile;
    if (pServer != NULL)
    delete pServer;
    session.Close();
    return FALSE;
    }

    strNewLocation = strNewLocation.Mid(nPlace + 10);
    nPlace = strNewLocation.Find('\n');
    if (nPlace > 0)
    {
    strNewLocation = strNewLocation.Left(nPlace);
    }

    if(strNewLocation.Find("http://",0)<0)
    {
    // strURL = OnConversionURL(strURL, strNewLocation);
    }
    else
    {
    strURL = strNewLocation;
    }
    pFile->Close();
    delete pFile;
    pServer->Close();
    delete pServer;
    }
    return true;
    }这是上次你的代码,我试了,查询反馈的状态码总是200
      

  16.   

    希望大家都UPUP,早日解决这个问题,相信对大家都有用的
      

  17.   

    理论上 只要点击就可以出现下载对话框的链接 是可以下载下来的 不过要仔细分析他的下载原理,
    是asp重定向,还是html 的自动转向等等 模拟ie就行了