download a file from a https server

download a file from a https server

Postby lucasdebeltran » Thu Sep 19, 2013 3:00 pm

Hello,

Has anyone donwloaded a file from an https, not http, such as https://www.myserver.com/da.txt?.

Thanks.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: download a file from a https server

Postby reinaldocrespo » Thu Sep 19, 2013 9:36 pm

Yes, and it works very nicely. I'm consuming https webservices using TIpClientHttp that inherits from tIpClient class from xharbour. You will need to download libeay32.dll, ssleay32.dll from OpenSSL. Then create the .lib from .dll and link to your app. You will also need to distribute these two dlls with your apps. I got all the information from the xharbour ng.

Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: download a file from a https server

Postby Silvio.Falconi » Fri May 30, 2014 10:14 am

can I see a test sample please ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: download a file from a https server

Postby reinaldocrespo » Fri May 30, 2014 1:11 pm

Sure, here is sample code:

The snippet below creates an object of the class InmediataWs to send a message to a web service and receive a response from it. SendRealTimeMessage() does the sending. Right after sending, it waits for a response that gets saved into property cResponse of the class.

Code: Select all  Expand view

...
   oImWs := InmediataWs():InitRealTime()  

   IF oImWs == NIL   ;RETURN NIL ;ENDIF
   
   oImWs:isSilent := isSilent
   oImWs:cMessage := MemoRead( cFileName )
   oImWs:SendRealTimeMessage()
   
   cRet := oImWs:cResponse
   oImWs:End()
 


The class itself may send/receive files or send/receive realtime messages. In the code below I show the methods of interest to you (only sending and receiving messages on realtime):
Code: Select all  Expand view

CLASS InmediataWs

   DATA aFiles    AS ARRAY INIT {}
   DATA aRoutedFiles AS ARRAY INIT {}
   DATA aResponse AS ARRAY INIT {}
   DATA aRespPages  AS ARRAY INIT {}

   DATA cUserName, cPassword
   DATA cMessage, cResponse

   DATA lShowProgress  INIT .F.
   DATA lShowConnected INIT .F.
   DATA isSilent INIT .F.
   
   DATA oHttp, oXml, oMeter

   METHOD InitRealTime()
   METHOD InitFileTransfer()
   METHOD End()
   
   METHOD SendFiles()
   METHOD GetResponse()
   METHOD GetRoutedFiles()
   
   METHOD SendRealTimeMessage()
   METHOD GetRealTimeMessage()
   
END CLASS


//---------------------------------------------------------------------------
METHOD InitRealTime( oMeter ) CLASS InmediataWs
   LOCAL isLogHttpProgress := GetValFromRepository( "X12WebService", "LogProgress", "NO" ) $ "YES,.T., TRUE,Y"
   LOCAL nTimeOut := VAL( GetValFromRepository( "X12WebService", "TimeOut", "30000", "Timeout in milliseconds" ) )
   LOCAL cUserName:= GetValFromRepository( "X12WebService", "UserName", "UserName" )
   LOCAL cPassword:= GetValFromRepository( "X12WebService", "Password", "Pass" )
   LOCAL cUrl := GetValFromRepository( "X12WebService", "RealTime_Eligibility_Url", ;
                  'https://www.inmediata.com/webservices/editransfer/edirealtime.asmx' )

   TRY
      ::oHttp := tIPClientHTTP():new( cUrl, isLogHttpProgress )
   CATCH
      MsgStop( "Missing SSL libs or no access to https was found.", "Check Installation" )
      RETURN NIL
   END
   
   IF ::oHttp == NIL    ;RETURN NIL    ;ENDIF

   ::ohttp:cConnetion:='Keep-Alive' // set to keep alive
   ::ohttp:bChunked := .T.
   ::oHttp:nConnTimeOut := nTimeOut
   ::cUserName := cUserName
   ::cPassword := cPassword

   ::oMeter := oMeter

   IF ::oMeter != NIL
      ::oMeter:nTotal := 100
      ::oMeter:Show()
      ::oHTTP:exGauge := { | nAt, nTotal, oSelf| ::oMeter:Set( ( Max( nAt, 0.00001 ) / Max( nTotal, 0.00001 ) ) * 100 ) }
   ENDIF

   IF ::oHttp:open()
   
      ::oHttp:hFields[ 'Content-Type'] := 'application/soap+xml; charset=utf-8'
      RETURN SELF

   ENDIF
   
RETURN NIL


//---------------------------------------------------------------------------
METHOD End() CLASS InmediataWs

   IF ::oMeter != NIL   ; ::oMeter:hide() ; ENDIF

   IF ::oHttp != NIL
      ::oHttp:Close()
      ::oHttp := NIL
   ENDIF

   ::oXml := NIL

   hb_gcAll( .T. )
   
RETURN NIL


//---------------------------------------------------------------------------
METHOD SendRealTimeMessage() CLASS InmediataWs
   LOCAL cPost
   
   cPost := ;
      '<?xml version="1.0" encoding="utf-8"?>'+;
      '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'+;
      '  <soap12:Header>'+;
      '    <AuthenticationHeader xmlns="https://www.inmediata.com/ws/EdiRealTime/">'+;
      '      <Username>' + ::cUserName + '</Username>'+;
      '      <Password>' + ::cPassword + '</Password>'+;
      '    </AuthenticationHeader>'+;
      '  </soap12:Header>'+;
      '  <soap12:Body>'+;
      '    <SendRealTime xmlns="https://www.inmediata.com/ws/EdiRealTime/">'+;
      '      <X12Data>' + ::cMessage + '</X12Data>'+;
      '    </SendRealTime>'+;
      '  </soap12:Body>'+;
      '</soap12:Envelope>'


      IF ::oHttp:Post( cPost ) ;::GetRealTimeMessage()   ;ENDIF

     
RETURN NIL

//---------------------------------------------------------------------------
METHOD GetRealTimeMessage() CLASS InmediataWs
   LOCAL oXmlDoc := TXmlDocument():New()// HBXML_STYLE_NOESCAPE )
   LOCAL cResponse
   LOCAL oXmlNode, cRet


   //::oHttp:bChunked := .T.
   //::oHttp:nLength := 32000
   cResponse := ::oHttp:ReadAll()
   //logfile( "trace.log", { cResponse, ::oHttp:bChunked, ::oHttp:nConnTimeout, ::oHttp:cConnetion } )


   oXmlDoc:Read( cResponse )

   oXmlNode := oXmlDoc:FindFirst( "RealTimeResponse" )
   IF oXmlNode != NIL   ;cRet := oXmlNode:cData  ;ENDIF

   oXmlNode := NIL
   oXmlDoc  := NIL

   ::cResponse := cRet

RETURN cRet

 


Hope that helps,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: download a file from a https server

Postby Baxajaun » Fri Aug 12, 2016 5:00 am

Hi Reinaldo,

please, could you publish a sample downloading a file from https server ? I need to download files from googledrive.

Thanks in advance !

Best regards,
User avatar
Baxajaun
 
Posts: 968
Joined: Wed Oct 19, 2005 2:17 pm
Location: Gatika. Bizkaia

Re: download a file from a https server

Postby ukoenig » Fri Aug 12, 2016 1:12 pm

Hi Reinaldo,
please, could you publish a sample downloading a file from https server ? I need to download files from googledrive.
Thanks in advance !


Maybe with a included login to download from my homepage ?

With all tested solutions I got problems !!!

regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: download a file from a https server

Postby reinaldocrespo » Fri Aug 12, 2016 2:06 pm

Hello Uwe;

I think you are asking if I can write sample code to download a file from your webpage. If that is the case, please send username and password to gain access to the service. Also, is this a SOAP 1.1 or 1.2 web service? If it is a Web Service then you should have a .WSDL or service description for the service. Please notice my class consumes Web Services. A web service makes itself available over the internet and uses a standardized XML messaging system. XML is used to encode all communications. For example, a client invokes a web service by sending an XML message, then waits for a corresponding XML response. Login information is sent in XML following your .WSDL specifications. Likewise a file request is sent using XML formatted according to WSDL for the request, and so on.

If your server does not provide web services then it is a totally different solution. I'm pretty sure I've seen plenty of other successful (may I dare say also "trivial") samples on this forum to send and capture http output.

If the problem is only connecting to https pages versus http, then it is probably related to the lack of linking SSL libs to you app. I'm using ssleay32.lib + libeay32.lib open source libraries on my link script. Please also notice I'm using xharbour tIpClientHttp() class.

Does this help?

Best regards,


Reinaldo.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: download a file from a https server

Postby ukoenig » Fri Aug 12, 2016 2:17 pm

Reinaldo,

thank You very much for the infos

with the solution from < Stephan Haupt >
I can connect to my homepage
but a given ZIp-file to download returns NIL from the server ( NOT found )
the rest is working fine.
Maybe I can detect inside the class where the problem comes from.

The connection works !

METHOD New (cIP, cUser, cPW, cFTPFolder, cZIPFile, cLocalDir, nFlags) CLASS TUpdate
DEFAULT cIP := "localhost",;
cUser := "anonymous",;
cPW := "anonymous@localhost",;
cFtpFolder := "/",;
cZipFile := "",;
cLocalDir := cFilePath( GetModuleFileName( GetInstance() ) ) + "Updates\" ,;
nFlags := 0


regards
Uwe :roll:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 63 guests