如何在下载之前检查 JPG url 是否存在,以避免异常?
procedure TForm1.Button1Click(Sender: TObject);
var
FS: TFileStream;
Url, FileName: String;
I, C: Integer;
begin
for I := 1 to 1000 do
begin
Url := 'http://www.mysite.com/images/' + IntToSTr(I) + '/Image.jpg';
FileName := 'C:\Images\' + IntToStr(I) + '.jpg';
FS := TFileStream.Create(FileName, fmCreate);
try
try
IdHTTP1.Get(Url);
c := IdHTTP1.ResponseCode;
if C = 200 then
IdHTTP1.Get(Url, FS);
except
end;
Application.ProcessMessages;
finally
Fs.Free;
end;
end;
end;