Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting a file
Message
From
01/10/2002 11:39:12
Fabian Belo
Independent Developer
Argentina
 
 
To
01/10/2002 11:28:55
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Internet applications
Title:
Miscellaneous
Thread ID:
00706372
Message ID:
00706400
Views:
24
This message has been marked as the solution to the initial question of the thread.
PROCEDURE VFPHTTP
LPARAMETER cURL, cNameFich
*** Definición de constantes básicas
#DEFINE INTERNET_OPEN_TYPE_PRECONFIG     0
*** Declaración de funciones del API
DECLARE LONG GetLastError ;
	IN WIN32API
DECLARE INTEGER InternetCloseHandle ;
	IN "wininet.dll" ;
	LONG     hInet
DECLARE LONG InternetOpen ;
	IN "wininet.dll" ;
	STRING   lpszAgent, ;
	LONG     dwAccessType, ;
	STRING   lpszProxyName, ;
	STRING   lpszProxyBypass, ;
	LONG     dwFlags
DECLARE LONG InternetOpenUrl ;
	IN "wininet.dll" ;
	LONG    hInet, ;
	STRING  lpszUrl, ;
	STRING  lpszHeaders, ;
    LONG    dwHeadersLength, ;
    LONG    dwFlags, ;
    LONG    dwContext
DECLARE LONG InternetReadFile ;
	IN "wininet.dll" ;
	LONG     hFtpSession, ;
	STRING  @lpBuffer, ;
	LONG     dwNumberOfBytesToRead, ;
	LONG    @lpNumberOfBytesRead
*** Apertura
nInternet = InternetOpen( ;
	"pruebavfp", ;
	INTERNET_OPEN_TYPE_PRECONFIG, ;
	"", "", 0 )
IF nInternet = 0
	MESSAGEBOX( "Error: " ;
		+ LTRIM( STR( GetLastError() ) ) ;
		+ " en InternetOpen.", 16 )
	
	RETURN 
ENDIF
*** Abrir la URL
nFichHTTP = InternetOpenUrl ( ;
	nInternet, ;
	cUrl, ;
	NULL, 0, 0, 0 )
IF nFichHTTP = 0
	MESSAGEBOX( "Error: " ;
		+ LTRIM( STR( GetLastError() ) ) ;
		+ " en InternetOpenUrl.", 16 )
	InternetCloseHandle( nInternet )
RETURN
ENDIF
*** Abir el fichero en el cliente
nFich = FCREATE( cNameFich )
*** Declarar las variables necesarias
nTama = 0
nLen = 1
*** Bucle de lectura
DO WHILE nLen # 0
	cBuffer = REPLICATE( CHR(0), 2048*2 )
	*** Leer del fichero en el servidor
	InternetReadFile(nFichHTTP,	@cBuffer, LEN( cBuffer ),@nLen ) 
	*** Escribir el fichero en el cliente
	*FWRITE( nFich, SUBSTR( cBuffer, 1, nLen ) )
	FWRITE( nFich, cBuffer )
	*** Aumentar el tamaño total
	nTama = nTama + nLen
	WAIT WIND "Recibidos " + LTRIM( STR( nTama ) ) NOWAIT
	*Aqui defines el tamano maximo que deseas.. si lo quitas, logicamente te bajara TODA la URL
	*Si exploró más de 30 K de un sitio finaliza.
	IF ntama>=30000
		WAIT "Finalizo por tamaño mayor a 30 k" WINDOW nowait
		EXIT
	ENDIF 
ENDDO
*WAIT CLEAR
*** Cerrar el fichero local
FCLOSE( nFich )
*** Cierre del uso del API
InternetCloseHandle( nInternet )
Uso en tu prg: vfphttp(urlactual, tmpfileM)
"Since I've read that alcohol is bad... I quit reading."
Me


http://www.fabianbelo.com.ar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform