Horizon wrote:Is it possible to show progress bar (for example in message bar) while reading at ReadAll() method?Sorry, I don't know.
I download big files from www. Users confuse if there is a problem or not.
Patrick
Horizon wrote:Is it possible to show progress bar (for example in message bar) while reading at ReadAll() method?Sorry, I don't know.
I download big files from www. Users confuse if there is a problem or not.
Hi,
Where can i find the more documentation about TIpClientHttp. Is it from Windows Controls or someone writes it?
Thanks
.
.
.
// oProg : Progress Bar is created before
cURL := "http://www.test.be/test.txt"
cSaveAs := "newfile.txt"
nFileSize := Get_File_Size(cURL)
IF wfReadURL(cURL, cSaveAs, oProg, nFileSize)
... File is there AND downloaded as cSaveAs
ELSE
... File is not there
ENDIF
.
.
.
FUNCTION wfSaveURL(cUrl, cSaveAs, oProg, nFileSize)
LOCAL oConn, lReturn:=.T.
DEFAULT oProg := 0
IF Upper(Left(cUrl,4))#"HTTP"
cUrl:="http://"+cUrl
ENDIF
TRY
oConn := TipClientHttp():New(TURL():New(cUrl))
oConn:nConnTimeout := 20000
IF !EMPTY(oProg) .and. !EMPTY(nFileSize)
oConn:exGauge := { | done, size| wfProgress(done, size, oProg ) }
oProg:SetRange( 0, 99 )
ENDIF
IF oConn:Open(cURL)
oConn:ReadToFile(cSaveAs,,nFileSize)
oConn:Close()
ENDIF
CATCH
lReturn := .F.
END
RETURN lReturn
function wfProgress(nReceived,nTotalSize,ooProg)
ooProg:SetPos(INT(nReceived/nTotalSize*100)+1)
SysRefresh()
return
function Get_File_Size(cURL)
LOCAL cBuffer, cRequest, cResponse, nBytes, pSocket, aRequest
LOCAL crlf := CHR(13)+CHR(10), Result := 0, oUrl
// initialize sockets system and connect to server
DEFAULT cURL:=""
oUrl := tURL():New( cUrl )
IF Empty( oUrl )
Return 0
ENDIF
IF Lower( oUrl:cProto ) <> "http"
Return 0
ENDIF
INetInit()
pSocket := INetConnect( oUrl:cServer, 80 )
IF INetErrorCode( pSocket ) <> 0
? "Socket error:", INetErrorDesc( pSocket )
INetCleanUp()
RETURN 0
ENDIF
crlf := INETCRLF()
// send HTTP request to server
cRequest := "HEAD "+oUrl:BuildAddress() + " HTTP/1.1" + CRLF + ;
"Host: "+oUrl:cServer+ CRLF + ;
"User-Agent: HTTP-Get-File-Size" + CRLF + ;
"Connection:close" + CRLF + ;
CRLF
nBytes := INetSend( pSocket, cRequest )
cBuffer := Space(4096)
cResponse:= ""
// get HTTP response from server
DO WHILE ( nBytes > 0 )
nBytes := INetRecv( pSocket, @cBuffer )
cResponse += Left( cBuffer, nBytes )
cBuffer := Space(4096)
ENDDO
// disconnect and cleanup memory
INetClose( pSocket )
INetCleanUp()
aRequest := HB_ATokens(cResponse, CRLF)
clear
nAt := Ascan(aRequest,{|x|LEFT(LTRIM(X),15)="Content-Length:"})
IF nAt>0
Result := VAL(SUBSTR(aRequest[nAt],17))
ENDIF
RETURN RESULTIF wfReadURL(cURL, cSaveAs, oProg, nFileSize)
... File is there AND downloaded as cSaveAsIF wfSaveURL(cURL, cSaveAs, oProg, nFileSize)
... File is there AND downloaded as cSaveAsDEFAULT oProg := 0IF wfSaveURL(cURL, cSaveAs, oProg, nFileSize)
... File is there AND downloaded as cSaveAs@ 80, 010 PROGRESS oProg POSITION 0 SIZE 212, 12 PIXELDEFAULT oProg := 0#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local oDlg, oBtnDwn, oBtnOk
DEFINE DIALOG oDlg
@ 1, 1 BUTTON oBtnDwn PROMPT "Download" ACTION Download(oProg)
@ 2.5, 1 PROGRESS oProg POSITION 0 SIZE 100, 12
@ 3, 1 BUTTON oBtnOk PROMPT "Quit" ACTION oDlg:End()
ACTIVATE DIALOG oDlg CENTER
return nil
PROCEDURE Download
LOCAL cURL, cSaveAs, nFileSize
cURL := "http://www.fivetechsoft.com/files/utilities/prometheus.exe"
cSaveAs := "prometh.exe"
nFileSize := Get_File_Size(cURL)
IF wfSaveURL(cURL, cSaveAs, oProg, nFileSize)
? "Downloaded" // ... File is there AND downloaded as cSaveAs
ELSE
? "Can not downloaded " //... File is not there
ENDIF
RETURN
FUNCTION wfSaveURL(cUrl, cSaveAs, oProg, nFileSize)
LOCAL oConn, lReturn:=.T.
DEFAULT oProg := NIL
DEFAULT nFileSize := 0
IF Upper(Left(cUrl,4))#"HTTP"
cUrl:="http://"+cUrl
ENDIF
TRY
oConn := TipClientHttp():New(TURL():New(cUrl))
oConn:nConnTimeout := 20000
IF !EMPTY(oProg) .and. !EMPTY(nFileSize)
oConn:exGauge := { | done, size| wfProgress(done, size, oProg ) }
oProg:SetRange( 0, 99 )
ENDIF
IF oConn:Open(cURL)
oConn:ReadToFile(cSaveAs,,nFileSize)
oConn:Close()
ENDIF
CATCH
lReturn := .F.
END
RETURN lReturn
function wfProgress(nReceived,nTotalSize,ooProg)
ooProg:SetPos(INT(nReceived/nTotalSize*100)+1)
SysRefresh()
return
function Get_File_Size(cURL)
LOCAL cBuffer, cRequest, cResponse, nBytes, pSocket, aRequest
LOCAL crlf := CHR(13)+CHR(10), Result := 0, oUrl
// initialize sockets system and connect to server
DEFAULT cURL:=""
oUrl := tURL():New( cUrl )
IF Empty( oUrl )
Return 0
ENDIF
IF Lower( oUrl:cProto ) <> "http"
Return 0
ENDIF
INetInit()
pSocket := INetConnect( oUrl:cServer, 80 )
IF INetErrorCode( pSocket ) <> 0
? "Socket error:", INetErrorDesc( pSocket )
INetCleanUp()
RETURN 0
ENDIF
crlf := INETCRLF()
// send HTTP request to server
cRequest := "HEAD "+oUrl:BuildAddress() + " HTTP/1.1" + CRLF + ;
"Host: "+oUrl:cServer+ CRLF + ;
"User-Agent: HTTP-Get-File-Size" + CRLF + ;
"Connection:close" + CRLF + ;
CRLF
nBytes := INetSend( pSocket, cRequest )
cBuffer := Space(4096)
cResponse:= ""
// get HTTP response from server
DO WHILE ( nBytes > 0 )
nBytes := INetRecv( pSocket, @cBuffer )
cResponse += Left( cBuffer, nBytes )
cBuffer := Space(4096)
ENDDO
// disconnect and cleanup memory
INetClose( pSocket )
INetCleanUp()
aRequest := HB_ATokens(cResponse, CRLF)
clear
nAt := Ascan(aRequest,{|x|LEFT(LTRIM(X),15)="Content-Length:"})
IF nAt>0
Result := VAL(SUBSTR(aRequest[nAt],17))
ENDIF
RETURN RESULTHello All,
I am on Harbour 1.1.0dev (Rev. 10716)
I have hbtip.lib in my buildh.bat and all programs compile ok except when
I try to add turl code to my program.
If I add this to my program:
oConn := TipClientHttp():New(TURL():New(cUrl))
I get this error:
Error: Unresolved external '_pcre_config' referenced from H:\ZHARBOUR\LIB\HBRTL.LIB|hbregex
Error: Unresolved external '_pcre_stack_malloc' referenced from H:\ZHARBOUR\LIB\HBRTL.LIB|hbregex
Error: Unresolved external '_pcre_stack_free' referenced from H:\ZHARBOUR\LIB\HBRTL.LIB|hbregex
Any ideas?
Thanks
Dave,
You have to link Harbour hbpcre.lib
Was anybody able to run the example "horizon" posted?
For me it returns "Downloaded" but nothing wa sactualy downloaded.
Antonio,
hbpcre.lib fixed my problem, however now getting:
HB_FUN_INETINIT'
HB_FUN_INETCONNECT
HB_FUN_INETERRORCODE
HB_FUN_INETERRORDESC
I have hbtip.lib linking in.
I thought hbtip.lib had these functions?
Thanks
Hi !,
Can somebody send me the HBTIP.LIB for Harbour and their sources? I cna't connect to CVS...
Regards.
Dave,
You need to link XHB.lib
Antonio => Thanks a lot ![]()
Antonio,
Compiles great now, Thanks ![]()