Indy is not working anymore after update - delphi

I had all kind of problems with Indy and following someone’s recommendations (at stackoverflow) I have updated to the latest version of Indy - at least this is what I intended to do.
Before starting the installation, I have manually deleted all files containing the "indy" word from my Delphi and from registry. Then I have followed the standard install procedure: http://www.indyproject.org/sockets/Docs/Indy10Installation.en.aspx
Now the piece of code below is not working anymore. The code just returns FALSE;
function Download(CONST aSourceURL: string; CONST aDestFileName: string; OUT aErrm: String): Boolean;
VAR
Stream: TMemoryStream;
IDAntiFreeze: TIDAntiFreeze;
fIDHTTP : TIDHTTP;
begin
fIDHTTP := TIDHTTP.Create(NIL);
// fIDHTTP.ConnectTimeout:=5000; <- not recognized
fIDHTTP.ReadTimeout:= 1000;
fIDHTTP.HandleRedirects := TRUE;
fIDHTTP.AllowCookies := FALSE;
fIDHTTP.Request.UserAgent := 'Mozilla/4.0';
fIDHTTP.Request.Connection := 'Keep-Alive';
fIDHTTP.Request.ProxyConnection := 'Keep-Alive';
fIDHTTP.Request.CacheControl := 'no-cache';
IDAntiFreeze := TIDAntiFreeze.Create(NIL);
Stream := TMemoryStream.Create;
TRY
TRY
fIDHTTP.Get(aSourceURL, Stream);
{
if FileExists(aDestFileName)
then DeleteFile(PWideChar(aDestFileName)); }
Stream.SaveToFile(aDestFileName);
Result:= TRUE;
EXCEPT
On E: Exception do
begin
Result:= FALSE;
aErrm := E.Message + ' (' + IntToStr(fIDHTTP.ResponseCode) + ')';
end;
END;
FINALLY
Stream.Free;
IDAntiFreeze.Free;
fIDHTTP.Free;
END;
end;
There is any way to see which version of Indy I have installed?
Edit:
Also I get an "Unit idHTTP was compiled with a different version of IdException.IdException" message. Fixed.

You should first use the Delphi setup to uninstall the version of Indy that is installed with Delphi - then you can cleanup any remaining file. You should not start by cleaning folders and registry by hand.
Then you can install another version. Be aware some releases are "breaking"

Related

TIdHttpServer freezing when Active set to False after Windows Update

We have a Indy (version 10.6.1.5235) TIdHttpServer "service" that has worked well for years with Delphi 2007. After the most recent Windows Update (KB4338815 and KB4338830) we noticed the service freezes when TIdHttpServer is set to false.
I have included source code where TIdHttpServer is created. In our service "Stop" handler we set IdHttpServer1.Active to False and this is where it freezes. It seems Indy hangs when it is trying to close the http connections. Is there a work around?
Update One Per Remy Lebeau, I have created a Minimal, Complete, and Verifiable example. Here it is:
procedure TMainForm.Button1Click(Sender: TObject);
begin
memo1.clear;
iCall := 0;
IdHTTPServer1 := TIdHTTPServer.Create;
IdHTTPServer1.MaxConnections := 10;
IdHTTPServer1.AutoStartSession := True;
IdHTTPServer1.SessionState := True;
IdHTTPServer1.OnCommandGet := IdHTTPServer1CommandGet;
IdHTTPServer1.KeepAlive := False;
idHttpServer1.DefaultPort := 80;
if ReuseSocket.checked then
IDHTTPSERVER1.ReuseSocket := rsTrue;
IdHTTPServer1.Active := True;
end;
procedure TMainForm.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
iCall := iCall + 1;
if iCall mod 100 = 0 then
memo1.lines.add(inttostr(iCall)+ ' calls made');
AResponseInfo.ContentText := '<html><body>Hello There</body></html';
end;
procedure TMainForm.StopClick(Sender: TObject);
begin
try
IdHTTPServer1.Active := False;
memo1.lines.add('IdHTTPServer1.Active := False;');
except
on e: exception do
memo1.lines.add('Exception on IdHTTPServer1.Active := False; Message:'+e.message);
end;
end;
Application will run fine but once you click the "Stop" button which sets the IdHttpServer Active property to False it hangs.
You might have encountered this similar issue:
Windows 2012 R2 closesocket() hangs on listening socket
The issue was brought by patch from Microsoft KB4338815, which caused closesocket tо hang forever on Intel Xeon processors
That issue was fixed by uninstalling KB4338815, which you do have installed. So try uninstalling that KB on your system and see if it solves your issue.

Routine for proxy change does not work on delphi 10.2 Tokyo

I am using using the Raises routine to configure use proxy within the system.
It works perfectly in delphi in version 7. In Delphi 10.2 (Tokyo), even compiling without errors, when calling the routine informs that the proxy is not responding (being that the proxy is ok and worked in delphi 7 call).
Would anyone have any idea what might be going on?
function ApplyProxy(proxy: string):Boolean;
var
MyInternetProxyInfo: PInternetProxyInfo;
begin
try
Result:=False;
proxy:=Trim(proxy);
MyInternetProxyInfo:=New(PInternetProxyInfo);
try
if proxy = EmptyStr then
MyInternetProxyInfo^.dwAccessType := INTERNET_OPEN_TYPE_DIRECT else
begin
MyInternetProxyInfo^.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
MyInternetProxyInfo^.lpszProxy := PAnsiChar(Trim(proxy));
MyInternetProxyInfo^.lpszProxyBypass := PAnsiChar('<local>');
end;
Result:=InternetSetOption(nil, INTERNET_OPTION_PROXY, MyInternetProxyInfo,
SizeOf(MyInternetProxyInfo^));
finally
Dispose(MyInternetProxyInfo);
end;
except
Result:=False;
end;
end;
In Delphi 10.2 Tokyo strings are unicode, and the compiler will warn that
PAnsiChar(Trim(proxy));
is
W1044 Suspicious typecast of string to PAnsiChar.
and this will not work when executed. Convert the string to an AnsiString first.
For example:
MyInternetProxyInfo^.lpszProxy := PAnsiChar(AnsiString(Trim(proxy)));
As suggested by LU-RD, I changed the routine and started running on tokio 10.2 update 3.
function ApplyProxy(proxy: string):Boolean;
var
MyInternetProxyInfo: PInternetProxyInfo;
begin
try
Result:=False;
proxy:=Trim(proxy);
MyInternetProxyInfo:=New(PInternetProxyInfo);
try
if proxy = EmptyStr then
MyInternetProxyInfo^.dwAccessType := INTERNET_OPEN_TYPE_DIRECT else
begin
MyInternetProxyInfo^.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
MyInternetProxyInfo^.lpszProxy := PAnsiChar(AnsiString(Trim(proxy)));
MyInternetProxyInfo^.lpszProxyBypass := PAnsiChar('<local>');
end;
Result:=InternetSetOption(nil, INTERNET_OPTION_PROXY, MyInternetProxyInfo, SizeOf(MyInternetProxyInfo^));
finally
Dispose(MyInternetProxyInfo);
end;
except
Result:=False;
end;
end;

Error connecting with SSL using IdHttp Indy

I have a problem in IdHttp using Indy (Delphi).
I try to using IdHttp to post XML in web service SOAP, but dont work. Return "Error connecting with SSL." in IdSSLOpenSSL.Connect#1437 from indy.
My code is simple:
procedure TForm1.Button1Click(Sender: TObject);
var
vRequest : TStringStream;
s : String;
begin
vRequest := TStringStream.Create((Memo1.Lines.Text));
try
IdHTTP1.Host := edHost.Text;
IdHTTP1.Request.ContentLength := length(Memo1.Lines.Text);
IdHTTP1.Request.ContentType := edContentType.Text;
IdHTTP1.Request.CustomHeaders.Text := 'SOAPAction: "removed for safe"'#13#10;
IdHTTP1.request.CacheControl := 'no-cache';
IdHTTP1.Request.AcceptEncoding := edAccept.Text;
IdHTTP1.HTTPOptions := [hoKeepOrigProtocol];
IdHTTP1.ProtocolVersion := pv1_1;
Memo2.Clear;
try
s := IdHTTP1.post(Edit1.Text, vRequest);
Memo2.Lines.Text := s;
except
on e: EIdHTTPProtocolException do begin
Label1.Caption := e.Message;
MEMO2.LINES.TEXT := e.Message;
end;
on e:Exception do begin
Label1.Caption := e.Message;
MEMO2.LINES.TEXT := e.Message;
end;
end;
requestHeaders.Lines.Text := IdHTTP1.Request.RawHeaders.Text;
responseHeaders.Lines.Text := IdHTTP1.Response.RawHeaders.Text;
finally
vRequest.Free;
end;
end;
In exe folder contain libeay32.dll and ssleay32.dll. Any sugestion?
I Used delphi 5, but in delphi 7 is the same problem.
By default, the SSLVersions property of TIdSSLIOHandlerSockOpenSSL is set to enable only TLS 1.0 1. But many websites are starting to phase out TLS 1.0 and only accept TLS 1.1+. So try enabling TLS 1.1 and TLS 1.2 in the SSLVersions property and see if it helps.
1: there is an open ticket in Indy's issue tracker to also enable TLS 1.1 and TLS 1.2 by default.
On a side note, there are some further tweaks you should make to your code:
do not assign any values to TIdHTTP's Host or ContentLength properties. They are populated automatically by TIdHTTP.
if you set the AcceptEncoding property manually, make sure NOT to include deflate or gzip unless you have a Compressor assigned to TIdHTTP, otherwise it will fail to decode a compressed response. You really should not assign anything to AcceptEncoding unless you are prepared to handle custom encodings. The Compressor handles deflate/gzip and TIdHTTP will update AcceptEncoding accordingly if a Compressor is assigned and ready for use.
use the CustomHeaders.Values property to set individual headers, not the CustomHeaders.Text property.
you do not need to catch EIdHTTPProtocolException explicitly, since that exception handler is not doing anything extra that the more generic Exception handler is not doing.
the RawHeaders property is a TStringList descendant, so it is more efficient to use Lines.Assign(RawHeaders) instead of Lines.Text := RawHeaders.Text.
Try this:
procedure TForm1.Button1Click(Sender: TObject);
var
vRequest : TStringStream;
s : String;
begin
IdHTTP1.Request.ContentType := edContentType.Text;
IdHTTP1.Request.CustomHeaders.Values['SOAPAction'] := 'removed for safe';
IdHTTP1.Request.CacheControl := 'no-cache';
IdHTTP1.HTTPOptions := [hoKeepOrigProtocol];
IdHTTP1.ProtocolVersion := pv1_1;
Memo2.Clear;
try
vRequest := TStringStream.Create(Memo1.Lines.Text);
try
s := IdHTTP1.Post(Edit1.Text, vRequest);
finally
vRequest.Free;
end;
Memo2.Lines.Text := s;
except
on e: Exception do begin
Label1.Caption := e.Message;
Memo2.Lines.Text := e.Message;
end;
end;
RequestHeaders.Lines.Assign(IdHTTP1.Request.RawHeaders);
ResponseHeaders.Lines.Assign(IdHTTP1.Response.RawHeaders);
end;

delphi 2006 indy https post time out

I have to use Delphi 2006. I have to use Indy 10.1.5 - comes with Delphi 2006 or not, but I have to use these versions! I found an example how to use indy SSL https get but now I completely lost my head and close to to do another 'bad day' video!
Finally, the SSL library loaded without any problem.
But... Why I get always 'EidReadTimeout with message 'Read Timeout'
here is my code:
var
IdHTTP1: TIdHTTP;
ParamStringList: TStringList;
s1: String;
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocketOpenSSL;
begin
IdHTTP1 := TIdHTTP.Create(nil);
IdSSLIOHandlerSocket1 := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
IdSSLIOHandlerSocket1.ReadTimeout := 10000;
IdHTTP1.IOHandler := IdSSLIOHandlerSocket1;
IdHTTP1.ConnectTimeout := 10000;
IdSSLIOHandlerSocket1.SSLOptions.Method := sslvSSLv23; // Which one is the good for...
IdSSLIOHandlerSocket1.SSLOptions.Mode := sslmClient;
IdSSLIOHandlerSocket1.SSLOptions.VerifyMode := [];
IdSSLIOHandlerSocket1.SSLOptions.VerifyDepth := 0;
ParamStringList := TStringList.Create;
ParamStringList.Text := '';
s1 := IdHTTP1.Post('https://msp.f-secure.com/web-test/common/test.html', ParamStringList);
Memo1.Text := s1;
ParamStringList.Free;
IdSSLIOHandlerSocket1.Free;
IdHTTP1.Free;
end;
Any idea? What can I missed?
I changed the timeout between 3 and 100 seconds, but no changes when I tried to ran my code.
Thanks in advance!

Problems with authorization after upgrading from Delphi 2005 to 2010 using Indy http (idHTTP1.Get)

I'm upgrading from Delphi 2005 to Delphi 2010.
I'm having this problem : the following procedure works well on D2005 but on D2010 I got always the result :
<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
<BODY><H1>401 Unauthorized</H1>
Your client does not have permission to get URL /axis-cgi/date.cgi from this server.
</BODY></HTML>
On the procedure, I try to connect twice because on D2005, sometimes I got an Unauthorized answer at my first try, and then I can connect at the second time with no problem. With D2010 I always get the Unauthorized answer.
The Url = 'http://user:pass#xxx.xxx.xxx.xxx/axis-cgi/date.cgi?action=get'
function TViewCameraForm.HttpGet(idHTTP : TidHTTP; Url : AnsiString): AnsiString;
Var
Res : AnsiString;
Begin
idHTTP1.Disconnect;
try
Res := idHTTP1.Get(Url);
If Pos('Unauthorized', Res) > 0 Then
Res := idHTTP1.Get(Url);
Result := Res;
except
on E: EIdHTTPProtocolException do begin
Result := E.ErrorMessage
end;
on E: Exception do begin
Result := E.message;
end;
end;
End;
Thanks
Sam
Did you try to authenticate using Basic Auth?
...
idHTTP1.Request.BasicAuthentication := True;
idHTTP1.Request.Username := 'user';
idHTTP1.Request.Password := 'pass';
Res := idHTTP1.Get(Url);
(using user:pass#website does not conform to the HTTP specification btw)

Resources