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]
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;
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?
Request.UserAgent
of yourIdHTTP1
component e.g. toMozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1
and you'll be fine. The server is rejecting you (in a formal way) just because you're acting as a defaultMozilla/3.0 (compatible; Indy Library)
agent (quite a cruel policy, but it does). – VervainGet
response as a string. Since you're obviously downloading a file, that you'll not show in a text form (why would you show icon as a text file), but you'll maybe save it or manipulate with it as with a file, you can use theGet
overload, which receives the response to a stream. – Vervain