T
tianzhen
Unregistered / Unconfirmed
GUEST, unregistred user!
对于链接: http://210.77.223.14/www.rar
取到的http状态码依次为200,404,200,404,...交替进行,为什么这么诡异啊?
附程序:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,wininet;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function CheckUrl(url:string ;TimeOut: integer):string;
var
hSession, hfile: hInternet; //uses wininet
dwindex,dwcodelen :dword;
dwcode:array[1..20] of char;
Err1: integer;
j: integer;
ProxyServer: string;
ProxyPort: Integer;
begin
Result := '000';
dwcode[1]:=#0;
hfile:=nil;
hSession := InternetOpen('InetURL:/1.0',INTERNET_OPEN_TYPE_DIRECT,nil, nil, 0); //'Mozilla/4.0'
InternetSetOption(hSession, Internet_OPTION_CONNECT_TIMEOUT, @TimeOut, SizeOf(TimeOut)); //超时
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(400);
end else break;
end;
dwIndex := 0;
dwCodeLen := 10;
if HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex) then
begin
if pchar(@dwcode)='404' then result:='404';
if pchar(@dwcode)='200' then result:='200';
end;
if assigned(hfile) then InternetCloseHandle(hfile);
InternetCloseHandle(hsession);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to 10 do begin
memo1.Lines.Add(checkurl('http://210.77.223.14/www.rar',30000));
end;
end;
end.
{
不正常(交替返回200和404):
http://210.77.223.14/www.rar
http://bbs.yqzone.com/www.rar
http://down.tsopen.com/www.rar
http://bulo.u2unet.com/www.rar
正常(返回200):
http://ourqzone.com/www.rar
http://newsgame.7su.com/www.rar
http://lib.cqnu.edu.cn/www.rar
http://online.fjrtvu.edu.cn/www.rar
}
取到的http状态码依次为200,404,200,404,...交替进行,为什么这么诡异啊?
附程序:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,wininet;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Function CheckUrl(url:string ;TimeOut: integer):string;
var
hSession, hfile: hInternet; //uses wininet
dwindex,dwcodelen :dword;
dwcode:array[1..20] of char;
Err1: integer;
j: integer;
ProxyServer: string;
ProxyPort: Integer;
begin
Result := '000';
dwcode[1]:=#0;
hfile:=nil;
hSession := InternetOpen('InetURL:/1.0',INTERNET_OPEN_TYPE_DIRECT,nil, nil, 0); //'Mozilla/4.0'
InternetSetOption(hSession, Internet_OPTION_CONNECT_TIMEOUT, @TimeOut, SizeOf(TimeOut)); //超时
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(400);
end else break;
end;
dwIndex := 0;
dwCodeLen := 10;
if HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex) then
begin
if pchar(@dwcode)='404' then result:='404';
if pchar(@dwcode)='200' then result:='200';
end;
if assigned(hfile) then InternetCloseHandle(hfile);
InternetCloseHandle(hsession);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to 10 do begin
memo1.Lines.Add(checkurl('http://210.77.223.14/www.rar',30000));
end;
end;
end.
{
不正常(交替返回200和404):
http://210.77.223.14/www.rar
http://bbs.yqzone.com/www.rar
http://down.tsopen.com/www.rar
http://bulo.u2unet.com/www.rar
正常(返回200):
http://ourqzone.com/www.rar
http://newsgame.7su.com/www.rar
http://lib.cqnu.edu.cn/www.rar
http://online.fjrtvu.edu.cn/www.rar
}