我做了一个软件用于下载。用的是
CString strUrl;
fileGet=(CHttpFile*)sess.OpenURL(LPCTSTR(strUrl));
又用
pHttpConn = session.GetHttpConnection(LPCTSTR(strServer), nPort))
fileGet = pHttpConn->OpenRequest(CHttpConnection::HTTP_VERB_GET, LPCTSTR(strObject));
试了一次可是当我在一个CEdit里输入网址(http://www.abc.com/def.php?ghi=123)时,下载正常。网址可用。可是我把这个网址存到一个TXT文件里时,用file.ReadString(strUrl);读出再下载,就不能下载了。请问我的TXT应该存储成什么格式的?
UTF-8,unicode,ascii?

解决方案 »

  1.   

    先看读取出来的字符串是不是正确,如果工程用了unicode,可以把txt格式设置unicode试试
      

  2.   

    大家帮忙看看吧。程序都是MFC做的。
    用这段写了一个列表文件{
    UpdateData(true);
    CStdioFile file2;
    CString outfilename;
    CString outhtml;
    int filelist = 0;
    int iout,j;
    char drive[_MAX_DRIVE];
    char dir[_MAX_DIR];
    TCHAR exeFullPath[MAX_PATH];
    GetModuleFileName(NULL,exeFullPath,MAX_PATH);
    _splitpath(exeFullPath, drive, dir, NULL,NULL);
    do
    {
    outfilename.Format("%s%sout%d.lst", drive, dir,filelist);
    filelist++;
    }
    while (PathFileExists(outfilename));
    file2.Open(outfilename,CFile::modeCreate| CFile::modeWrite);
    for (j=0;j<i;j++)
    {
    file2.WriteString(m_strFornt);//前缀如“HTTP://”
    file2.WriteString(AstrOut.GetAt(j));//AstrOut就是URL数组
    file2.WriteString("\n");
    }
    file2.Close(); outhtml.Format("%d个文件被处理!;采集到%d个有效数据",ifile,i);
    MessageBox(outhtml);
    }然后在另一个程序中用这段读出来BOOL CXiazaiDlg::MyRead()
    {
    UpdateData(true);
    CString strTmp;
    CString FileTitle;
    CString filename; m_Source.MakeLower();
    if (m_Source.Left(7) == "http://")//如果输入是网址直接下载
    {
    arrUrl.Add(m_Source);
    if (!PathFileExists(m_OutPath))
    {
    arrOutFile.Add(m_OutPath);

    else
    {
    if (m_Source.Find('?') == -1)//有的网址有“?”今天就遇到了。
    {
    strTmp = m_Source.Right(m_Source.GetLength()-1-m_Source.ReverseFind('/'));

    else
    {
    strTmp = m_Source.Right(m_Source.GetLength()-1-m_Source.ReverseFind('?'));
    strTmp += ".htm";
    }
    filename.Format("%s\\%s",m_OutPath,strTmp);
    arrOutFile.Add(filename);
    }
    iNum++;

    else if (PathFileExists(m_Source))//输入的是列表文件名
    {
    CStdioFile filein;
    if (filein.Open(m_Source,CFile::modeRead))
    {
    while (filein.ReadString(strTmp))//这里读取列表,读的没有错误
    {
    if (strTmp != "")
    {
    arrUrl.Add(strTmp);
    if (strTmp.Find('?') == -1)
    {
    strTmp = strTmp.Right(strTmp.GetLength()-1-strTmp.ReverseFind('/'));

    else
    {
    strTmp = strTmp.Right(strTmp.GetLength()-1-strTmp.ReverseFind('?'));
    strTmp += ".htm";
    }
    filename.Format("%s\\%s",m_OutPath,strTmp);

    arrOutFile.Add(filename);
    iNum++;
    }
    }
    if (iNum == 1)
    {
    if (!PathFileExists(m_OutPath))
    {
    arrOutFile[0] = m_OutPath;
    }
    }
    filein.Close();
    }
    else
    {
    MessageBox("列表读取失败!");
    }
    }
    else
    {
    return false;
    }
    return true;
    }最后下载时,如果输入先前输出的文件,下载就错误。;
    如果直接输入一个文件里的URL,就不会错。
    文件用"UE"换了好几次格式了。都不行。
      

  3.   

    能出错的也就这么几条。
    1、网址用CString直接写。
    2、ReadString()读出来的最后一个字符是'\r'。
    3、PHP?有时侯分大小写。‘A’和‘a’是不一样的。
    4、有些网页如论坛类的需要Cookies
    5、有些网站的Cookies一会儿时间不连接就过期,需要经常的连接。