delphi 如果判断一个网络文件是否存在?


本文整理自网络,侵删。

 function CheckUrl(url: string): Boolean;
var
hSession,hfile: hInternet;
dwindex, dwcodelen: dword;
dwcode: array[1..20] of Char;
res: PChar;
begin
Result := false;
if Pos('http://', LowerCase(url)) = 0 then url := 'http://' + url;
hSession := InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
if Assigned(hsession) then
begin
hfile := InternetOpenUrl(hsession, PChar(url), nil, 0, INTERNET_FLAG_RELOAD, 0);
dwIndex := 0;
dwCodeLen := 10;
HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex);
res := PChar(@dwcode);
Result := (res = '200') or (res = '302'); //200,302未重定位标志
if Assigned(hfile) then
InternetCloseHandle(hfile);
InternetCloseHandle(hsession);
end;
end;

相关阅读 >>

Delphi 给变量加引号

Delphi Delphi 学习大师qq群讨论的字符串位置替换方法

Delphi字符串拆分(字符数限制)

Delphi winapi: shellexecute - 打开外部程序或文件

Delphi xe10.x 快捷失灵解决办法

Delphixe7关于android 检测屏幕是否处于关闭状态

Delphi-xe5-开发 android uri简介

Delphi xe6 android拨号函数

Delphi中如何将鼠标放置在控件上就给予提示信息

Delphi 批量日期格式化

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...