Solved

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

Posted on 2013-01-26
3
2,639 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 38823164
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
ID: 38823301
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 27

Expert Comment

by:Sinisa Vuk
ID: 38825032
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction and Prerequisites This article describes methods for detecting whether a client browser accepts and returns HTTP cookies and whether the client browser runs JavaScript.  Most client browsers will, by default, be configured to use cooki…

710 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