Solved

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

Posted on 2013-01-26
3
2,577 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 26

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 26

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction This warning has to be one of the most commonly issued warnings in the history of PHP.  The article explains why this warning arises and what to do to mitigate the problem. How this Happens HTTP headers include many different kinds…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

837 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