function CheckUrl(url: string; TimeOut: integer = 5000): boolean;
var
hSession, hfile, hRequest: hInternet;
dwindex, dwcodelen: dword;
dwcode: array[1..20] of char;
res: pchar;
re: integer;
Err1: integer;
j: integer;
begin
{uses wininet;}
if pos('http://', lowercase(url)) = 0 then
url := 'http://' + url;
Result := false;
InternetSetOption(hSession, Internet_OPTION_CONNECT_TIMEOUT, @TimeOut, 4);
hSession := InternetOpen('Mozilla/4.0', INTERNET_OPEN_TYPE_PRECONFIG, nil,
nil, 0);
//设置超时
if assigned(hSession) then
begin
j := 1;
while True do
begin
hfile := InternetOpenUrl(hSession, pchar(url), nil, 0,
INTERNET_FLAG_RELOAD, 0);
if hfile = nil then
begin
j := j + 1;
Err1 := GetLastError;
if j > 5 then
break;
if (Err1 <> 12002) or (Err1 <> 12152) then
break;
sleep(2);
end
else
begin
break;
end;
end;
dwindex := 0;
dwcodelen := 10;
HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodelen, dwindex);
res := pchar(@dwcode);
re := strtointdef(res, 404);
case re of
400..450: Result := false;
else
Result := True;
end;
if assigned(hfile) then
InternetCloseHandle(hfile);
InternetCloseHandle(hSession);
end;
end;

delphi检查url是否有效的方法的更多相关文章

  1. [Delphi]检查URL是否有效的函数

    function CheckUrl(url: string): boolean; var hSession, hfile, hRequest: hInternet; dwindex, dwcodele ...

  2. 用delphi检查网络连接状态3种方式

    用delphi检查网络连接状态3种方式 用delphi检查网络连接状态 检测计算机是否联网比较简单的做法可以通过一个 Win32 Internet(WinInet) 函数 InternetCheckC ...

  3. asp.net C#检查URL是否有效

    我们有时候需要对用户输入的网站(URL)进行有效性检查,  代码如下 复制代码 function CheckUrl(str) {    var RegUrl = new RegExp();    Re ...

  4. [转]Delphi调用cmd的两种方法

    delphi调用cmd的两种方法vars:string;begins:='cmd.exe /c '+edit1.Text+' >c:\1.txt';winexec(pchar(s),sw_hid ...

  5. DELPHI新的变量的声明方法

    DELPHI新的变量的声明方法 从DELPHI 10.3.1开始支持新的变量声明方法: procedure TForm1.查询1Click(Sender: TObject); begin var ur ...

  6. (java)Jsoup爬虫学习--获取网页所有的图片,链接和其他信息,并检查url和文本信息

    Jsoup爬虫学习--获取网页所有的图片,链接和其他信息,并检查url和文本信息 此例将页面图片和url全部输出,重点不太明确,可根据自己的需要输出和截取: import org.jsoup.Jsou ...

  7. jsp Request获取url信息的各种方法比较

    从Request对象中可以获取各种路径信息,以下例子: 假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 String p ...

  8. paip.uapi 获取网络url内容html 的方法java php ahk c++ python总结.

    paip.uapi 获取网络url内容html 的方法java php ahk c++ python总结. 各种语言总结比较,脚本php.python果然是方便.简短,实用. uapi : get_w ...

  9. ASP.NET URL伪静态重写实现方法

    ASP.NET URL伪静态重写实现方法 首先说下,ASP.NET URL伪静态只是将~/a_1.html指向到了~/a.aspx?ID=1,但a.aspx还是真实存在的,你不用./a_1.html来 ...

随机推荐

  1. 对弈类游戏的人工智能(4)--游戏AI的落地

    前言: 对弈类游戏的智能算法, 网上资料颇多, 大同小异. 然而书上得来终觉浅, 绝知此事要躬行. 结合了自己的工程实践, 简单汇总整理下. 一方面是对当年的经典<<PC游戏编程(人机博弈 ...

  2. android使用Webview上传图片

    package com.example.webview; import java.io.File; import android.net.Uri;import android.os.Bundle;im ...

  3. 字符串匹配--manacher算法模板

    manacher算法主要是处理字符串中关于回文串的问题的,它可以在 O(n) 的时间处理出以字符串中每一个字符为中心的回文串半径,由于将原字符串处理成两倍长度的新串,在每两个字符之间加入一个特定的特殊 ...

  4. CentOS6.8 MySQL 5.6实现主从复制

    主库操作 1.将mysqldump命令添加到/usr/bin中 ln -s /application/mysql/bin/mysqldump /usr/bin/ 2.开启master上的log-bin ...

  5. 安卓中自定义并使用Volley框架请求网络

    大家好,今天我们讲一下如何使用Volley框架请求网络,为何要使用Volley框架,这就要先说一下使用Volley框架请求网络的优点了,volley是易于定制的,即你可以根据需求来设定volley框架 ...

  6. LeetCode Potential Thought Pitfalls

    Problem Reason Reference Moving ZeroesSort Colors Corner cases   Shortest Word Distance Thought: 2 p ...

  7. windows server 2008服务器 做raid0

    dell服务器,启动后,根据提示按F10进入raid设置,设置成raid0 我们的服务器是4块硬盘,每块600G,做raid0时,生成一个虚拟磁盘vdisk. 做完raid之后,做OS部署 重启服务器 ...

  8. [补充工程统计case]科技活动经费sql2014

    select bd_glorgbook.glorgbookcode,bd_glorgbook.glorgbookname, gl_detail.explanation, bd_accsubj.disp ...

  9. mysql 的 infobright 数据库的 mediumblob 显示不了数据

    需要修改mysql的配置文件: /var/www/html/phpmyadmin/config.inc.php 增加: $cfg['ProtectBinary'] = FALSE; 即可

  10. Discuz有关问题解决办法汇总

    1.Can not write to cache files, please check directory ./data/ and ./data/cache/ . 无法写入缓存 解决办法:在sour ...