I'm developing a .dll file (to be more specific a Browser Helper Object - BHO). And I need to receive some settings hosted in one TXT file. To read this TXT file, I'm using IdHTTP, but when I do .get into the TXT address, it just stop everything. I'll paste the code below:
procedure TMyClass.ReadTXT;
function LoadTxt(HTTP: TidHTTP; Body: TStringList; URLTxt: string): boolean;
begin
try
Body.Text:= HTTP.Get(URLTxt);
Result := true;
except
Result := false;
end;
end;
var
HTTP: TidHTTP;
Body: TStringList;
ValidTXT: boolean;
Line: string;
i, aux: integer;
begin
HTTP := TIDHttp.Create(Nil);
try
HTTP.ConnectTimeout:= 5000;
HTTP.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1';
Body := TStringList.Create;
try
ValidTXT := false;
i := 0;
while (ValidTXT = false) and (i < TXTs.Count) do
begin
if (LoadTXT(HTTP, Body, TXTs.Strings[i]) = true) and (Body.Count > 0) then
begin
...
end;
So in the beginning of this procedure I've a function, to see if I successfully got some TXT, because as you can see I'm using a TStringList called TXTs. So, I add 3 TXTs addresses into this TStringList, and try to connect till find some valid address. But in the first line of the funcion (Body.Text:= HTTP.Get(URLTxt);) it just stops even with a valid TXT address... Someone have a clue about what is happening?
I figured out what's happening. But don't know why... When I set:
HTTP.ConnectTimeout:= 10000;
HTTP.Request.UserAgent:= 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1';
the .Get method don't work... If someone can clarify this to me, i'll be very thankfully.