Martin Melka
Martin Melka

Reputation: 7799

Why doesn't LoadFromStream show anything after TIdHTTP.Get?

I just began having problems with Indy. For some weird reason, even this very basic procedure doesn't work:

procedure TForm1.Button1Click(Sender: TObject);
var ID: TIdHTTP;
    ms: TMemoryStream;
begin
  ID:=TIdHTTP.Create();
  ms:=TMemoryStream.Create;

  ID.HandleRedirects:=true;

  ID.Get('http://www.google.com',ms);
  Memo1.Lines.LoadFromStream(ms);
end;

Nothing gets added to the Memo1. SizeOf(ms) returns 4.

I even reinstalled Indy, still nothing. My project definitely worked before, but doesn't download anything from any page now. I wonder, what is the problem?

Upvotes: 2

Views: 853

Answers (2)

Mihai Limbășan
Mihai Limbășan

Reputation: 67836

Odd, that code should work, assuming similar code worked before.

Sorry, but I have to ask:

  1. Have you confirmed that accessing that very same URL from that very same machine under that very same user account works from within a browser? Try both a third party browser as well as IE. Can't recall offhand whether Indy uses WinHTTP but it's possible, and a problem affecting WinHTTP such as some piece of malicious software or a BHO will affect IE but won't affect, for example, Firefox, Chrome or Opera.

  2. Have you tried turning off your antivirus system and/or your firewall (should you use any non-builtin firewall)? Many antivirus packages include Winsock LSPs or NDIS interceptors for realtime network traffic scanning and might interfere.

  3. Finally, failing all that, can you try to fetch that very same URL using a Windows port of wget or cURL, just to see if other non-browser HTTP clients exhibit issues as well?

Upvotes: 0

user497849
user497849

Reputation:

try calling

MS.Position := 0; 

before

Memo1.Lines.LoadFromStream(ms);

also, the size of the stream can be found out by invoking the "Size" property like so

ShowMessage('size of stream = ' + IntToStr(ms.size) + ' bytes');

Upvotes: 13

Related Questions