在浏览器中直接键入地址http://download.sina.com.cn/cgi-bin/download.cgi?s_id=3103&href=0可以下载某文件wzbeta90.exe。但使用Delphi控件TNMhttp时执行语句:NMHTTP1.Get(http://download.sina.com.cn/cgi-bin/download.cgi?s_id=3103&href=0)成功。但是没有下载到文件,而是取到该网页的源文件信息。分析取到的源文件信息,包含:http://hnpy.onlinedown.net/down/wzbeta90.exe。再直接调用NMHTTP1.Get(http://hnpy.onlinedown.net/down/wzbeta90.exe)执行成功,也没有下载到文件wzbeta90.exe。
请问使用HTTP协议如何下载到这个文件呢?

解决方案 »

  1.   

    加了语句后NMHTTP1.InputFileMode :=true;
    可以下载了但是下载途中报错:Socket send aborted
    这是什么原因啊???
      

  2.   

    我这里有一个类似的程序
    不过我出差在外 大约明天回去
    如果需要给我发短信或者
    [email protected]
      

  3.   

    NMHTTP1.InputFileMode := true;
    NMHTTP1.OutputFileMode := false;
    NMHTTP1.Body:='wzbeta90.exe' ;
    NMHTTP1.Get('http://hnpy.onlinedown.net/down/wzbeta90.exe');
      

  4.   

    网络中下载一个指定文件    
      uses 
    URLMon, ShellApi;function DownloadFile(SourceFile, DestFile: string): Boolean;begintryResult := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;exceptResult := False;end;end;procedure TForm1.Button1Click(Sender: TObject);const// URL LocationSourceFile = 'http://www.google.com/intl/de/images/home_title.gif';// Where to save the fileDestFile = 'c:image.gif';beginif DownloadFile(SourceFile, DestFile) thenbeginShowMessage('Download succesful!');// Show downloaded image in your browserShellExecute(Application.Handle, PChar('open'), PChar(DestFile),PChar(''), nil, SW_NORMAL)endelseShowMessage('Error while downloading ' + SourceFile)end;// Minimum availability: Internet Explorer 3.0// Minimum operating systems Windows NT 4.0, Windows 95******************************2.}usesWininet;function DownloadURL(const aUrl: string): Boolean;varhSession: HINTERNET;hService: HINTERNET;lpBuffer: array[0..1024 + 1] of Char;dwBytesRead: DWORD;beginResult := False;// hSession := InternetOpen( 'MyApp', INTERNET_OPEN_TYPE_DIRECT, nil, nil, 0);hSession := InternetOpen('MyApp', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);tryif Assigned(hSession) thenbeginhService := InternetOpenUrl(hSession, PChar(aUrl), nil, 0, 0, 0);if Assigned(hService) thentrywhile True dobegindwBytesRead := 1024;InternetReadFile(hService, @lpBuffer, 1024, dwBytesRead);if dwBytesRead = 0 then break;lpBuffer[dwBytesRead] := #0;Form1.Memo1.Lines.Add(lpBuffer);end;Result := True;finallyInternetCloseHandle(hService);end;end;finallyInternetCloseHandle(hSession);end;end;******************************在Delphi中如何从网络中提取一个文件到本地计算机中,如提取<BR> http://www.abcdefg.com/software/a.zip到本地指定的目录中?在窗体中添加1个TNMHTTP控件(在FastNet页)然后在随便那个Button什么的下面加入如下代码: NMHTTP1.InputFileMode := ture;NMHTTP1.Body := '本地文件名';NMHTTP1.Header := 'Head.txt';NMHTTP1.OutputFileMode := FALSE;NMHTTP1.ReportLevel := Status_Basic;NMHTTP1.Proxy := '代理服务器的IP地址';NMHTTP1.ProxyPort := '代理服务器的端口号';With NMHTTP1.HeaderInfo doBeginCookie := '';LocalMailAddress := '';LocalProgram := '';Referer := '';UserID := '用户名称';Password := '用户口令';End;NMHTTP1.Get(‘http://www.abcdefg.com/software/a.zip’);试试吧,Delphi的目录中有TNMHTTP控件的例子。NT4+,Win95+,IE3+,你可以用URL Moniker的功能。uses URLMon;...OleCheck(URLDownloadToFile(nil,'URL','Filename',0,nil));其中最后一个参数你还可以传入一个IBindStatusCallback的实现以跟踪下载进度或控制中止下载。简单的场合一句话就搞定了。--回复得分 0--BTW, URL Moniker封装了大多数URL,而不是像NMHTTP那样封装协议,因此你可以用URLDownloadToFile下载HTTP,FTP甚至本地文件和局域网文件,还有其他的custom moniker,比如MSITSTORE(MSDN Library的文档moniker实现)。 
     
     
      

  5.   

    谢谢各位了!
    delphi还真行!
    就3句话:
      nmhttp1.InputFileMode :=true
      nmhttp1.Body :='w2ksp4_cn.exe'
      NMhttp1.Get('http://download.microsoft.com/download/4/1/4/4140e2e0-0ad9-4438-ac52-da0e0429c0e6/w2ksp4_cn.exe')
    就把120M的w2ksp4给下下来了,而且平均速度30K/s
      

  6.   

    只是有时候下载途中报错:Socket  send  aborted  
    这是什么原因啊???  
      

  7.   

    只是有时候下载途中报错:Socket  send  aborted  
    这是什么原因啊???  
      

  8.   

    应该是连接不太稳定,中途断开连接了。
    如果断掉,你可以用 HTTP 的 Partial Content 方式续传的。
    用 D6/D7 的 Indy 组件要好点儿,更方便一些。
    TIdHTTPClient
      

  9.   

    对了,还要注意处理 HTTP 协议中重定向的问题。
    具体的你可以参考以下 RFC 2616/HTTP 1.1 协议。
    http://www.faqs.org/rfcs/rfc2616.html