DELPHI 检测URL地址是否有效


本文整理自网络,侵删。

 DELPHI 检测URL地址是否有效

function TForm1.CheckUrl(url: string):Boolean;
var
hSession, hfile, hRequest: 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;
{ Open an internet session }
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');
if Assigned(hfile) then
InternetCloseHandle(hfile);
InternetCloseHandle(hsession);
end;
end;

相关阅读 >>

Delphi把一个字符串中的某个子串,用另一个子串去替换

Delphi 获取 access 数据库所有表

Delphi tdirectory.getdirectories

Delphi http远程屏幕源码

Delphi 利用tmemorystream对象存取缓存

Delphi d10.x 在android 9及更高版本下使用Delphi获取设备序列号?

Delphi 10.3.3 启动cnpack ide 专家 cnwizards coreide260.bpl错误解决办法

Delphi 隐藏桌面图标和任务栏

Delphi 程序窗体最大化、组件居中显示代码

Delphi 网上获取北京时间验证码识别之中值滤波

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



打赏

取消

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

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

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

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

评论

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