//uses UrlMon; function DownloadFile(SourceFile, DestFile: string): Boolean; begin try Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0; except Result := False; end; end; procedure TForm1.Button1Click(Sender: TObject); begin if DownloadFile('http://www.xxx.com/a.gif', ExtractFilePath(Application.ExeName) + 'a.gif') then begin {再把文件内容拷贝到TStream} end; end;説明:先下載再看
procedure TForm1.Button1Click(Sender: TObject); var strm: TMemoryStream; begin strm := TMemoryStream.Create; try IdHTTP1.Get('http://www.xxx.com/a.gif', strm); finally Edit1.Text := IdHTTP1.Response.ResponseText; end; end;説明:也可用「TIdHTTP」控件直接将内容拷贝到TStream中。
另:又有问题请教: 为什么 (WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame') as IWebBrowser.Document.Url 及 (WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame') as IWebBrowser.Document.Location 的值有时是IFrame中页面的地址 有时又是主页面的地址 摸不着头脑,望各位大侠有以教我
另:又有问题请教: 为什么 (((WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame').item(0,0) as IWebBrowser).Document as IHTMLDocument2).Url 及 (((WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame').item(0,0) as IWebBrowser).Document as IHTMLDocument2).Location 的值有时是IFrame中页面的地址 有时又是主页面的地址 摸不着头脑,望各位大侠有以教我
function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
except
Result := False;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
begin
if DownloadFile('http://www.xxx.com/a.gif', ExtractFilePath(Application.ExeName) + 'a.gif') then begin
{再把文件内容拷贝到TStream}
end;
end;説明:先下載再看
var
strm: TMemoryStream;
begin
strm := TMemoryStream.Create;
try
IdHTTP1.Get('http://www.xxx.com/a.gif', strm);
finally
Edit1.Text := IdHTTP1.Response.ResponseText;
end;
end;説明:也可用「TIdHTTP」控件直接将内容拷贝到TStream中。
UrlDownloadToFile(...);是否支持全部Url协议,如file:// mshtml:// res://等
2: 同样,IdHTTP1.Get呢?另,以下代码执行总出错
function MyFun(...);
var Resp : TMemoryStream;
FileStream : TFileStream;
begin
HTTPReqResp1.URL := 'http://www.china.com';//
HTTPReqResp1.UseUTF8InHeader := true;
HTTPReqResp1.Send('');
Resp := TMemoryStream.Create;
Resp.SetSize(65535);
HTTPReqResp1.Receive(0,Resp);
出错在最后一句,即HTTPReqResp1.Receive(0,Resp);
错误信息为"无效句柄"
cronuz(cronus):
你给出的第一个方法,试过,可以,不过要存储临时文件,所以第二方法合理一些
为什么
(WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame') as IWebBrowser.Document.Url
及
(WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame') as IWebBrowser.Document.Location
的值有时是IFrame中页面的地址
有时又是主页面的地址
摸不着头脑,望各位大侠有以教我
为什么
(((WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame').item(0,0) as IWebBrowser).Document as IHTMLDocument2).Url
及
(((WebBrowser1.Document as IHTMLDocument2).all.tags('IFrame').item(0,0) as IWebBrowser).Document as IHTMLDocument2).Location
的值有时是IFrame中页面的地址
有时又是主页面的地址
摸不着头脑,望各位大侠有以教我