在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
相关资料: https://www.ogeek.cc/delphi/103143.html 使用Delphi XE将通过WinHTTP下载的文件保存到磁盘 https://www.cnblogs.com/huangjacky/archive/2009/12/30/1635830.html Delphi - 我的代码之简单封装WinHttpRequest
实例:下面这代码是我下载ZIP包时用到的,亲证可用。 {$APPTYPE CONSOLE} uses Variants,ActiveX,Classes,AxCtrls,WinHttp_TLB,SysUtils; function Download(const url,filename: String): Boolean; var http: IWinHttpRequest; wUrl: WideString; fs:TFileStream; HttpStream :IStream; sz,wr:Int64; FStatus : Integer; OleStream: TOleStream; begin try wUrl := url; http := CoWinHttpRequest.Create; http.open('GET',False); http.send(EmptyParam); FStatus := http.status; // 200=OK! result := FStatus=200; if result then begin HttpStream:=IUnknown(http.ResponseStream) as IStream; OleStream:= TOleStream.Create(HttpStream); try fs:= TFileStream.Create(FileName,fmCreate); try OleStream.Position:= 0; fs.CopyFrom(OleStream,OleStream.Size); finally fs.Free; end; finally OleStream.Free; end; end; except result := false; // do not raise exceptions. end; end; begin try Download('http://foo.html','C:\Foo\anyfile.foo'); except on E: Exception do Writeln(E.ClassName,': ',E.Message); end; end.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论