我编写了一个使用组件 IdHTTP 的 android 应用程序。问题出现在第十八个程序调用的时候。
var
Form2: TForm2;
XmlS: TStringlist;
MemoryS: TMemoryStream;
Host: string;
IdHTTP: TIdHTTP;
i: integer;
response: IXMLResponseType;
procedure ReadXML;
begin
inc(i);
XmlS.Clear;
MemoryS.Clear;
Form2.XMLDocument1.active := true;
IdHTTP.Request.Clear;
IdHTTP.HandleRedirects := true;
IdHTTP.Request.Username := 'adminqq';
IdHTTP.Request.Password := 'adminw';
IdHTTP.Request.BasicAuthentication := true;
Host := 'http://' + form1.EHost.text + '/da1.xml';
try
IdHTTP.Get(Host, MemoryS)
except
Form2.Label1.text := 'Http Error'
end;
MemoryS.Position := 0;
TEncoding.UTF8.ToString;
XmlS.LoadFromStream(MemoryS, TEncoding.UTF8);
Form2.XMLDocument1.LoadFromXML(XmlS.text);
response := Getresponse(Form2.XMLDocument1);
Form2.Label1.text := 'Temperature: ' + floattostr(response.Ia7 / 10) + '°' +
' Count: ' + inttostr(i);
Form2.XMLDocument1.active := false;
Form2.RoundRect1.Fill.Color := SwitchStatus(response.Out0);
Form2.RoundRect2.Fill.Color := SwitchStatus(response.Out1);
Form2.RoundRect3.Fill.Color := SwitchStatus(response.Out2);
Form2.RoundRect4.Fill.Color := SwitchStatus(response.Out3);
Form2.RoundRect5.Fill.Color := SwitchStatus(response.Out4);
end;
每第十八个过程调用关闭应用程序,没有错误消息。我试图只使用:
IdHTTP.Request.Clear;
IdHTTP.HandleRedirects := true;
IdHTTP.Request.Username := 'adminqq';
IdHTTP.Request.Password := 'adminw';
IdHTTP.Request.BasicAuthentication := true;
Host := 'http://' + form1.EHost.text + '/da1.xml';
try
IdHTTP.Get(Host);
except
Form2.Label1.text := 'Http Error'
end;
没有成功(其他主机,http文档)。怎么了?