delphi源码获取网络图片缓存的地址


delphi源码获取网络图片缓存的地址

uses WinINet;

Function TForm1.GetCacheVerifyCodeFile(VerifyCodeURL:String; Var CacheVerifyCodeFile:String):Boolean;
Var
lpEntryInfo: PInternetCacheEntryInfo;
dwEntrySize, dwLastError, Hwd: LongWORD;
i, j: Integer;
f: String;
Begin
Result := false;
dwEntrySize := 0;
j := 0;
CacheVerifyCodeFile := '';
FindFirstUrlCacheEntry(Nil, TInternetCacheEntryInfo(Nil^), dwEntrySize);
GetMem(lpEntryInfo, dwEntrySize);
Hwd := FindFirstUrlCacheEntry(Nil, lpEntryInfo^, dwEntrySize);
If Hwd <> 0 Then
Begin
Repeat
dwEntrySize := 0;
FindNextUrlCacheEntry(Hwd, TInternetCacheEntryInfo(Nil^), dwEntrySize);
dwLastError := GetLastError();
If dwLastError = ERROR_INSUFFICIENT_BUFFER Then
Begin
GetMem(lpEntryInfo, dwEntrySize);
If FindNextUrlCacheEntry(Hwd, lpEntryInfo^, dwEntrySize) Then
begin
If Pos(UpperCase(VerifyCodeURL), UpperCase(lpEntryInfo.lpszSourceUrlName)) > 0 Then
Begin
i := FileAge(lpEntryInfo.lpszLocalFileName);
If i > j Then
Begin
j := i;
f := lpEntryInfo.lpszLocalFileName;
End
Else
DeleteUrlCacheEntry(lpEntryInfo.lpszSourceUrlName);
End;
end;
End;
Application.ProcessMessages;
Until (dwLastError = ERROR_NO_MORE_ITEMS);

If FileExists(f) Then
Begin
CacheVerifyCodeFile := f;
Result := true;
End;
End;
FreeMem(lpEntryInfo);
FindCloseUrlCache(Hwd);
End;

可用于在缓存中的验证码图片,或者防盗链的图片的采集,嘿嘿。

此函数有两个参数,第一个是网络图片地址,第二个是本地缓存地址。第二个作为输出端口。


联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678