DELPHI 判断网站文件是否存在


本文整理自网络,侵删。

  uses wininet;

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;

procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckURL('http://www.delphitop.com/123.txt')then
showmessage('fang')
else
showmessage('error');
end;

相关阅读 >>

Delphi 弹出输入框的inputquery, inputquery 函数用法

Delphi 使用shgetfileinfo函数获取任何文件大图标

Delphi win10下message无法接收的问题

Delphi java 日期 转换 获取unix时间戳

Delphi xe5 android 发短信以及目录

Delphi incyear、incmonth、incweek、incday、inchour、incminute、incsecond、incmillisecond �c 增时

Delphi 查看内存数据的函数

Delphi 获取文件所在路径

Delphi版的base64转换函数(修改版)

Delphi第三方控件通用安装方法

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



打赏

取消

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

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

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

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

评论

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