Discussion:
idhttp download file problem with https
(too old to reply)
Axel
2006-09-14 15:52:46 UTC
Permalink
Hi
I use indi 7 and delphi 7

I try to download a file with https protocol with a function i write down,
that works with http protocol.
The files downloaded are empty (one time it downloaded a html file of the
site)
The link is something like:
https://bollettinoreport.poste.it/bollettinoreport/98331.zip?idRichiesta=98331
If i try to savetofile the link in the browser, it start the download with
the standard IE download windows.

I fault or missed something in the function or i fault the approch??
The indy version is too old??

T.i.a.
Axel



function GetWebFile(sUrl,LnomeCompletoOut:string):boolean;
var T:TMemoryStream;
idhttp1:tidhttp;
FSSL : TIdSSLIOHandlerSocket;
begin

result:=false;
idhttp1:=TIdHTTP.Create(nil);

if pos('https',sUrl)>0 then
begin
FSSL := TIdSSLIOHandlerSocket.Create(idhttp1);
idhttp1.IOHandler := FSSL;
end;

T:=TMemoryStream.create;
try
idHTTP1.Get(sURL,T);
T.SaveToFile(LnomeCompletoOut);
result:=true;
finally
T.Free;
FreeAndNil(idhttp1);
end;
end;
Remy Lebeau (TeamB)
2006-09-14 17:24:17 UTC
Permalink
Post by Axel
I use indi 7 and delphi 7
There is no Indy 7. Are you using Indy 9 or 10 instead?
Post by Axel
I try to download a file with https protocol with a function i write
down, that works with http protocol.
Try this code:

function GetWebFile(sUrl, LnomeCompletoOut: String): Boolean;
var
Strm: TStream;
HTTP: TIdHTTP;
begin
Result := False;
try
HTTP := TIdHTTP.Create(nil);
try
with TIdURI.Create(sURL) do
try
if AnsiSameText(Protocol, 'https') then
HTTP.IOHandler :=
TIdSSLIOHandlerSocket.Create(HTTP);
finally
Free.
end;

Strm := TFileStream.Create(LnomeCompletoOut, fmCreate);
try
HTTP1.Get(sURL, Strm);
Result := True;
finally
FreeAndNil(Strm);
end;
finally
FreeAndNil(HTTP);
end;
except
end;
end;
Post by Axel
The files downloaded are empty
Then the server is not sending any file data to begin with.
Post by Axel
one time it downloaded a html file of the site
That can happen if your request was invalid/erroneous, such that the server
is sending back an error page without using an HTTP error code. You need to
look at the response headers to know what the server actually sent before
you then use the data.
Post by Axel
If i try to savetofile the link in the browser, it start the download
with the standard IE download windows.
Is it possible that the server is expecting IE to be the only supported
browser? Many servers tailor their content to specific browsers. By
default, TIdHTTP does not report itself to be IE. If you run into this kind
of situation (which happens more often then you might think), you can change
the Request.UserAgent property to mimic IE's UserAgent.
Post by Axel
The indy version is too old??
That is another possibility.


Gambit
Axel
2006-09-15 07:33:19 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by Axel
I use indi 7 and delphi 7
There is no Indy 7. Are you using Indy 9 or 10 instead?
Sorry, I use Indy 9
Post by Remy Lebeau (TeamB)
Post by Axel
I try to download a file with https protocol with a function i write
down, that works with http protocol.
function GetWebFile(sUrl, LnomeCompletoOut: String): Boolean;
var
Strm: TStream;
HTTP: TIdHTTP;
begin
Result := False;
try
HTTP := TIdHTTP.Create(nil);
try
with TIdURI.Create(sURL) do
try
if AnsiSameText(Protocol, 'https') then
HTTP.IOHandler :=
TIdSSLIOHandlerSocket.Create(HTTP);
finally
Free.
end;
Strm := TFileStream.Create(LnomeCompletoOut, fmCreate);
try
HTTP1.Get(sURL, Strm);
Result := True;
finally
FreeAndNil(Strm);
end;
finally
FreeAndNil(HTTP);
end;
except
end;
end;
Post by Axel
The files downloaded are empty
Then the server is not sending any file data to begin with.
Post by Axel
one time it downloaded a html file of the site
That can happen if your request was invalid/erroneous, such that the server
is sending back an error page without using an HTTP error code. You need to
look at the response headers to know what the server actually sent before
you then use the data.
Post by Axel
If i try to savetofile the link in the browser, it start the download
with the standard IE download windows.
Is it possible that the server is expecting IE to be the only supported
browser? Many servers tailor their content to specific browsers. By
default, TIdHTTP does not report itself to be IE. If you run into this kind
of situation (which happens more often then you might think), you can change
the Request.UserAgent property to mimic IE's UserAgent.
Post by Axel
The indy version is too old??
That is another possibility.
Gambit
Axel
2006-09-15 08:45:44 UTC
Permalink
Post by Remy Lebeau (TeamB)
Post by Axel
The files downloaded are empty
Then the server is not sending any file data to begin with.
Post by Axel
one time it downloaded a html file of the site
That can happen if your request was invalid/erroneous, such that the server
is sending back an error page without using an HTTP error code. You need to
look at the response headers to know what the server actually sent before
you then use the data.
Post by Axel
If i try to savetofile the link in the browser, it start the download
with the standard IE download windows.
Is it possible that the server is expecting IE to be the only supported
browser? Many servers tailor their content to specific browsers. By
default, TIdHTTP does not report itself to be IE. If you run into this kind
of situation (which happens more often then you might think), you can change
the Request.UserAgent property to mimic IE's UserAgent.
The server (tomcat) is expecting clients previously authenticated with login
and pass.
The site is like a remote banking, so there are some security mechanism for
the session ecc... (i don't know how, what...)
Probably i must use twebbrowser as i use before I reach the download point
we are talking about, and with a external program interact with the IE
download windows (as i do in another application yet).
I don't like this solution, so i ask you some idea!!...

I try with version 10 but nothing.

Tia
Post by Remy Lebeau (TeamB)
Post by Axel
The indy version is too old??
That is another possibility.
Gambit
Remy Lebeau (TeamB)
2006-09-15 10:09:39 UTC
Permalink
Post by Axel
The server (tomcat) is expecting clients previously authenticated
with login and pass.
There you go then. You will have to simulate a login before you can then
downloaded protected files. What EXACTLY is the server expecting? Do you
have to fill in a web form? Or does the browser display a popup
user/password dialog instead?
Post by Axel
Probably i must use twebbrowser as i use before I reach the download
point we are talking about, and with a external program interact with
the IE download windows (as i do in another application yet).
You will not have to do that.


Gambit
Axel
2006-09-15 13:21:46 UTC
Permalink
Post by Remy Lebeau (TeamB)
There you go then. You will have to simulate a login before you can then
downloaded protected files. What EXACTLY is the server expecting? Do you
have to fill in a web form? Or does the browser display a popup
user/password dialog instead?
Post by Axel
Probably i must use twebbrowser as i use before I reach the download
point we are talking about, and with a external program interact with
the IE download windows (as i do in another application yet).
You will not have to do that.
Gambit
I try to explain all..
I use some function to interact with a IE browser windows. (some function
are written after)
I open a site, fill some field (user, pass, id) choose the desidered menu,
finally i make a order of some file.
The server after some time gets ready this files in a specific menu.
The html code of this page is written after.
At this point i would like to simply download this files without use the
webbrower method to skip the popup Ie download windows ecc..
Probably I have to "say" something to idhttp ....
Infact if i try to use the link
(https://bollettinoreport.poste.it/bollettinoreport/98422.zip?idRichiesta=98422
) from other Pc without log in, the file downloaded is empty. The situation
is similar or equal.
I think that there was many mechanism that protect the process and is very
difficult (or impossible) recreate all using tidhttp....but if you
contraddict me.... i will be the happiest man in this land!!

TIA


Function TScaricaImmaginiBp.SelezionaFinestra(LnomeFinestra:string):boolean;
var
k: Integer;
begin
result:=false;
ShellWindow := CoShellWindows.Create;
for k := 0 to ShellWindow.Count-1 do
try
if pos(lowercase(LnomeFinestra),lowercase((ShellWindow.Item(k) as
IWebbrowser2).LocationUrl))>0 then
begin
result:=true;
spDisp := ShellWindow.Item(k);
spDisp.QueryInterface(iWebBrowser2, WB1);
if WB1 <> nil then
begin
WB1.Document.QueryInterface(IHTMLDocument2, iDoc1);
if iDoc1 <> nil then
begin
WB1 := ShellWindow.Item(k) as ShDocVW_TLB.IWebbrowser2;
Document := WB1.Document;
// exit;
end;
end;
end;
except
end;

end;




function
TScaricaImmaginiBp.ConnettiEautentica(lCodiceAzienda,lUser,lPwd:string):boolean;
begin
result:=false;
ShellExecute(IeHndl, 'open',PChar(K_URL_AUTH1), nil, nil, SW_SHOWMINIMIZED);
if Assigned(FOnChangeState) then FOnChangeState(K_MSG01);

fTimer.Enabled:=true;
sleep(200);
if not Visibile then ManageWindow('BancoPostaImpresa',SW_HIDE);
repeat

Application.ProcessMessages;

if fStato=TimeOutEd then
begin
if Assigned(FOnChangeState) then
FOnChangeState(K_MSG10);
exit;
end;

if SelezionaFinestra('BancoPostaImpresa') then
begin
if Assigned(FOnChangeState) then FOnChangeState(K_MSG02);
if (
FillFormNoFrame(K_FORM_Id_azienda,lcodiceAzienda)
and FillFormNoFrame(K_FORM_user,luser)
and FillFormNoFrame(K_FORM_Pass,lPwd)

) then

if PremiButtonNoFrame('Entra') then
begin
fStato:=Autenticato;
fTimer.Enabled:=false;
result:=true;
if Assigned(FOnChangeState) then FOnChangeState(K_MSG03)
end;
end;
until ((fStato=TimeOutEd) or (fStato=Autenticato) or
(Application.Terminated ) );

end;






<html lang="it">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1 "/>
<LINK title="Sito WAI" rel="alternate" href="/wai/index.shtml" media="aural,
braille, tty"/>
<meta name="description" content="In questa pagina sono visualizzate le
liste di bollettini richieste. "/>
<meta name="keywords" content=""/>
<meta name="Author" content="Poste Italiane S.p.A."/>
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache"/>
<meta HTTP-EQUIV="Expires" CONTENT="-1"/><title>Poste Italiane - Bollettino
Report </title>
<SCRIPT LANGUAGE="JavaScript"
src="/bollettinoreport/posteBrnew.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">write_style_tag()</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
function invia(idRichiesta){
document.cancellaRichiestaForm.idRichiesta.value=idRichiesta;
document.cancellaRichiestaForm.submit();
}
</SCRIPT>

</head><body bgcolor="#ffffff" leftmargin="0" topmargin="10" marginwidth="0"
marginheight="10" onLoad="setVariables();checkLocation()">
<table border="0" cellPadding=0 cellspacing="0" width="99%" summary="tabella
che contiene l'intestazione dell'appalicazione"><tr><td rowspan="2"
width="254"><a href="http://www.poste.it/" target="_top"><img
src="/bollettinoreport/img/tb/logo_posteitaliane.gif" alt="Home Poste
Italiane" width="254" height="42" border="0"></a></td><td align="left"
width="90%"><script language="JavaScript">visData();</script></td><td
align="right" width="90%" height="21">&nbsp;</td></tr><tr
bgColor="#e8f404"><td>&nbsp;</td><td align="right"><img
src="/bollettinoreport/img/tb/fine.gif" alt="" width="25" height="21"
border="0"></td></tr><tr bgColor="#000099"><td>&nbsp;</td><td colspan="2"
align="right"><table border="0" cellPadding="4" cellspacing="0"
width="100%"><tr><td class=w10>&nbsp;</td></tr></table></td></tr></table>
<table border="0" cellpadding="0" cellspacing="0" width="99%"
height="72%"><tr valign="top"><td width="150"><div
style="width:150px;background-color:#ffffff;">&nbsp;</div>&nbsp;</td><td
width="95%">&nbsp;<br>&nbsp;



<table border="0" cellpadding="2" cellspacing="0" width="585"><tr
valign="top"><td width="585"><b class="blu12">Bollettino Report -
Esportazione risultati</b><br /><b>In questa pagina sono visualizzate le
liste di bollettini richieste.

</b><br></td>

</tr></table>
&nbsp;

<form name="cancellaRichiestaForm" method="post"
action="/bollettinoreport/cancellaRichiesta.do">
<input type="hidden" name="idRichiesta" value="">



<div class="cornice">
<table cellspacing="1" summary="Ricerca bollettini accreditati">
<tr valign="top">
<th>ID</th>
<th>Descrizione</th>
<th>Data richiesta</th>
<th>Data scadenza</th>
<th>Data fine lavorazione</th>
<th>Numero immagini</th>
<th>Utente</th>
<th>Stato</th>
<th>Elimina</th>
</tr>


<tr valign="top">
<td align="right"><strong>

<a href='98422.zip?idRichiesta=98422'>

98422

</a>

</strong></td>
<td> </td>
<td>14/09/2006 14:19:40</td>
<td>14/09/2006&nbsp;</td>
<td>14/09/2006 14:19:59</td>
<td align="right">218</td>
<td>consul</td>
<td>




<a href='98422.zip?idRichiesta=98422'><strong>disponibile</strong></a>
(scaduta)

</td>
<td align="center">

<a href="javascript:invia('98422')"><img
src="../bollettinoreport/img/ico/cancella.gif" border="0"></a>

</td>

</tr>



<tr valign="top">
<td align="right"><strong>

<a href='98337.zip?idRichiesta=98337'>

98337

</a>

</strong></td>
<td> </td>
<td>14/09/2006 13:05:40</td>
<td>14/09/2006&nbsp;</td>
<td>14/09/2006 13:06:01</td>
<td align="right">401</td>
<td>consul</td>
<td>



<a href='98337.zip?idRichiesta=98337'><strong>scaricata</strong></a>


</td>
<td align="center">

<a href="javascript:invia('98337')"><img
src="../bollettinoreport/img/ico/cancella.gif" border="0"></a>

</td>

</tr>



<tr valign="top">
<td align="right"><strong>

<a href='98331.zip?idRichiesta=98331'>

98331

</a>

</strong></td>
<td> </td>
<td>14/09/2006 13:03:19</td>
<td>14/09/2006&nbsp;</td>
<td>14/09/2006 13:03:54</td>
<td align="right">500</td>
<td>consul</td>
<td>




<a href='98331.zip?idRichiesta=98331'><strong>disponibile</strong></a>
(scaduta)

</td>
<td align="center">

<a href="javascript:invia('98331')"><img
src="../bollettinoreport/img/ico/cancella.gif" border="0"></a>

</td>

</tr>

---cut--

Loading...