让我们看看偏航能不能帮到我
假设有一个链接: www.example.com/test.html
打开时,它将显示0或1。
我需要获取该值。即:
if internet.value := 0 then ShowMessage('False') else ShowMessage('True');它可以使用indy组件或winsockets,我该怎么做呢?
发布于 2012-10-08 15:27:56
如果你谈论的是一个只包含一个整数值的纯文本文件,你可以使用Indy来实现,例如这样。当页面下载成功并且页面包含整数值时,以下函数返回True,否则返回False。请注意,我是在浏览器中编写的,所以它是未经测试的:
uses
IdHTTP;
function TryWebContentToInt(const AURL: string; out AValue: Integer): Boolean;
var
S: string;
IdHTTP: TIdHTTP;
begin
IdHTTP := TIdHTTP.Create(nil);
try
IdHTTP.HandleRedirects := True;
try
S := IdHTTP.Get(AURL);
Result := TryStrToInt(S, AValue);
except
Result := False;
end;
finally
IdHTTP.Free;
end;
end;和用法:
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
if TryWebContentToInt('http://example.com/page.html', I) then
ShowMessage('Value: ' + IntToStr(I))
else
ShowMessage('Page downloading failed or it doesn''t contain an integer value!');
end;https://stackoverflow.com/questions/12776304
复制相似问题