愚
愚鱼
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了个下网页的函数
function GetWebPage(const url: string; const FileName: string): string;
var
FileHandle: integer;
sWebPage: string;
Position: integer;
http: TIdHTTP;
Host: string;
begin
http := TIdHTTP.Create(Form1); //////////////////
http.HandleRedirects := true;
//extract host from URL
Host := copy(url, 8, length(url));
Position := pos('/', Host);
if Position <> 0 then
http.Host := trim(copy(Host, 1, Position - 1)) //8=Length('http://')+1
else
http.Host := trim(copy(Host, 1, length(Host)));
Form1.Edit1.Text := http.Host;
if Form1.EdtHost.Text <> '' then http.Host := Form1.EdtHost.Text;
try
try
FileHandle := FileCreate(FileName);
http.Connect(-1);
sWebPage := http.Get(trim(url));
FileWrite(FileHandle, sWebPage[1], length(sWebPage));
except
end;
finally
FileClose(FileHandle);
http.Disconnect;
http.Free;
end;
end;
用程序的可执行文件运行后可以完成所需要求
但如果在delphi7的环境下调试运行时政个网站网页的下载过程中要报n次两种错误分别是:
1、'project project3.exe raised execption class EidHTTPProtocolException with message HTTP/1.1 404 object Not Found'
按完回车程序就停在FileWrite(FileHandle, sWebPage[1], length(sWebPage));处,接着按F5程序继续执行
2、‘project project3.exe raised execption class EIdsocketError with message Socket Error #10060 connection timed out’
按完回车程序就停在sWebPage := http.Get(trim(url));处,接着按F5程序继续执行
这两种错误出现好多次但只要反复按回车键和F5键程序倒也能望城最终的结果,和用可执行文件运行的结果一样。
我查过一些资料这两种错误一种是“连接超时”;一种是错误是”文件打开读取失败“
我想用处理异常的方法再except中写些语句对这两种异常进行一下处理,但我在帮助中又找不到EidHTTPProtocolException的信息,不知道具体怎么写,或着各位大虾又没有什么能避免这种错误产生的好方法,十万火急希望多多帮忙。
function GetWebPage(const url: string; const FileName: string): string;
var
FileHandle: integer;
sWebPage: string;
Position: integer;
http: TIdHTTP;
Host: string;
begin
http := TIdHTTP.Create(Form1); //////////////////
http.HandleRedirects := true;
//extract host from URL
Host := copy(url, 8, length(url));
Position := pos('/', Host);
if Position <> 0 then
http.Host := trim(copy(Host, 1, Position - 1)) //8=Length('http://')+1
else
http.Host := trim(copy(Host, 1, length(Host)));
Form1.Edit1.Text := http.Host;
if Form1.EdtHost.Text <> '' then http.Host := Form1.EdtHost.Text;
try
try
FileHandle := FileCreate(FileName);
http.Connect(-1);
sWebPage := http.Get(trim(url));
FileWrite(FileHandle, sWebPage[1], length(sWebPage));
except
end;
finally
FileClose(FileHandle);
http.Disconnect;
http.Free;
end;
end;
用程序的可执行文件运行后可以完成所需要求
但如果在delphi7的环境下调试运行时政个网站网页的下载过程中要报n次两种错误分别是:
1、'project project3.exe raised execption class EidHTTPProtocolException with message HTTP/1.1 404 object Not Found'
按完回车程序就停在FileWrite(FileHandle, sWebPage[1], length(sWebPage));处,接着按F5程序继续执行
2、‘project project3.exe raised execption class EIdsocketError with message Socket Error #10060 connection timed out’
按完回车程序就停在sWebPage := http.Get(trim(url));处,接着按F5程序继续执行
这两种错误出现好多次但只要反复按回车键和F5键程序倒也能望城最终的结果,和用可执行文件运行的结果一样。
我查过一些资料这两种错误一种是“连接超时”;一种是错误是”文件打开读取失败“
我想用处理异常的方法再except中写些语句对这两种异常进行一下处理,但我在帮助中又找不到EidHTTPProtocolException的信息,不知道具体怎么写,或着各位大虾又没有什么能避免这种错误产生的好方法,十万火急希望多多帮忙。