Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Title # Comments Views Activity
Magic Software info 18 143
DBGrid or StringGrid ? 6 120
How to make Sign in, using Clientdataset? 1 33
Firemonkey Queue list 1 28
Introduction One of the frequent application design questions goes something like this: "How can I confirm when a client registers on my web site?" The registration might be for general use of a self-administered site like a forum, or for attend…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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