Solved

Using IdHTTP1.Get with Delphi and Indy 9/10 on a specific web server returns exception

Posted on 2013-01-26
3
2,392 Views
Last Modified: 2013-01-27
I've a problem receiving a favicon.ico from a specific web server using Delphi and Indy 9/10. Other servers do work fine. The problem is not with this web server, as wget command line utility gets the file correctly.

here is the output from wget:
c:\a>wget http://perforce.eigenbase.org:8080/favicon.ico
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = c:/progra~1/wget/etc/wgetrc
--2013-01-27 00:12:39--  http://perforce.eigenbase.org:8080/favicon.ico
Resolving perforce.eigenbase.org... 72.14.190.177
Connecting to perforce.eigenbase.org|72.14.190.177|:8080... connected.
HTTP request sent, awaiting response... 200 No headers, assuming HTTP/0.9
Length: unspecified
Saving to: `favicon.ico'

    [ <=>                                   ] 2.862       --.-K/s   in 0s

2013-01-27 00:12:40 (143 MB/s) - `favicon.ico' saved [2862]

Open in new window

Here is my Delphi Indy 9/10 example code. It generates a "Connection Closed Gracefully" Exception, and the result is an empty string.
procedure TForm1.Button1Click(Sender: TObject);
var s: string;
begin
  s := '';
  try
  	s := IdHTTP1.Get('http://perforce.eigenbase.org:8080/favicon.ico');
  except
     on E: Exception do
     begin
          {$IFDEF DEBUG}ShowMessage('get error:'+E.Message){$ENDIF};
     end;
  end;
  ShowMessage(IntToStr(Length(s)));
end;

Open in new window

If I try the same code with a different server, for example:

s := IdHTTP1.Get('http://www.google.com/favicon.ico');

everything works just fine.

Is there a workaround to get the http://perforce.eigenbase.org:8080/favicon.ico file using IdHTTP1.Get from the server?
0
Comment
Question by:Casady
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
Sinisa Vuk earned 500 total points
Comment Utility
Indy is sometimes a pain .... It produces exception but internally is all ok.
Try this way...
...
      s :='';
      try
          s := IdHTTP1.Get('http://perforce.eigenbase.org:8080/favicon.ico');
          IdHTTP1.Disconnect(False); 
          IdHTTP1.IOHandler.InputBuffer.Clear;
        except
           on E: EIdConnClosedGracefully do 
           begin
              s := IdHTTP1.IOHandler.InputBufferAsString;
              if Length(Trim(s))=0 then
              begin
                s := IdHTTP1.ResponseText;
              end;
              IdHTTP1.Disconnect(False);
              IdHTTP1.IOHandler.InputBuffer.Clear;
           end else 
           begin
             ....
           end;
        end;
        ShowMessage(s);
...

Open in new window

0
 

Author Comment

by:Casady
Comment Utility
Well, I have accepted the solution too soon. :/

On the first look it works ok, because I've compared the first 20 bytes of the data I receive with wget and the data in IdHTTP1.ResponseText.

But the wget file is 2862 bytes, the content of IdHTTP1.ResponseText is only 2316 bytes. :(
0
 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
As I said ... it is a pain... Try to use something else which works fine... Other way to download file:
http://www.swissdelphicenter.ch/torry/showcode.php?id=412
http://delphi.about.com/od/internetintranet/a/get_file_net.htm
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now