Imaginons que sur le site "http://toto.free.fr", il y a un fichier "1.txt".
Comment mettre dans a$ le contenu de "http://toto.free.fr/1.txt" ??
Acces a un fichier internet
Re: Acces a un fichier internet
en utilisant le webgadget !!SPH a écrit :Imaginons que sur le site "http://toto.free.fr", il y a un fichier "1.txt".
Comment mettre dans a$ le contenu de "http://toto.free.fr/1.txt" ??

je supose que si ça marche pour du html ça doit fonctionner pour un fichier Txt !!
JE viens de creer un txt dans mon site, et ce code va chercher a le lire !

dans ce code toute la page pointé se retrouve dans la variable
"Url2Text(#Site)" , donc un simple a$=Url2Text(#Site), et voila

;/ Author : Pille
; Proxy like this : "192.168.0.1:8080"
Global Site.s= "http://michel.dobro.free.fr/bidouilles/SPH.txt"
;Global Site.s="http://michel.dobro.free.fr/index.htm"
; toute la page web est dans "Url2Text(#Site)
; toute la page web est dans "Url2Text(#Site)
; toute la page web est dans "Url2Text(#Site)
; toute la page web est dans "Url2Text(#Site)
; toute la page web est dans "Url2Text(#Site)
ProcedureDLL.s Url2Text2(Url.s, OpenType.b,ProxyAndPort.s)
; 1 INTERNET_OPEN_TYPE_DIRECT Resolves all host names locally.
; 0 INTERNET_OPEN_TYPE_PRECONFIG Retrieves the proxy Or direct configuration from the registry.
; 4 INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY Retrieves the proxy Or direct configuration from the registry And prevents the use of a startup Microsoft JScript Or Internet Setup (INS) file.
; 3 INTERNET_OPEN_TYPE_PROXY Passes requests To the proxy unless a proxy bypass list is supplied And the name To be resolved bypasses the proxy. In this Case, the function uses INTERNET_OPEN_TYPE_DIRECT.
isLoop.b=1
INET_RELOAD.l = $80000000
hInet.l=0
hURL.l=0
Bytes.l=0
Buffer.s= Space (2048 )
RES.s= ""
hInet = InternetOpen_ ( "" , OpenType, ProxyAndPort, "" , 0)
hURL = InternetOpenUrl_ (hInet, Url, #Null , 0, INET_RELOAD, 0)
Repeat
InternetReadFile_ (hURL,@Buffer, Len (Buffer), @Bytes)
If Bytes = 0
isLoop=0
Else
RES = RES + Left (Buffer, Bytes)
EndIf
Until isLoop=0
InternetCloseHandle_ (hURL)
InternetCloseHandle_ (hInet)
ProcedureReturn RES
EndProcedure
ProcedureDLL.s Url2Text(Url.s)
ProcedureReturn Url2Text2(Url,1, "" )
EndProcedure
;/ Test
OpenWindow (0,10,10,800,600, "resultat" , #PB_Window_SystemMenu )
CreateGadgetList ( WindowID (0))
EditorGadget (2, 10, 10, 800,580)
AddGadgetItem (2, -1, Url2Text(Site.s))
Repeat
Event= WindowEvent ()
Until Event = #PB_Event_CloseWindow
c'est clair.Dr. Dri a écrit :bah n'utilise pas de fenêtre, t'as une procédure toute faite je vois pas ton problemeSPH a écrit :J'aurais aimé plutot le telecharger en toute transparence plutot que d'ouvrir une quelconque fenetre...
Dri
après la procédure toute faite, voici le code source tout fait.
Code : Tout sélectionner
;-
;- Win32 - Wininet.lib
;-
Enumeration 0 ; #INET_
#INET_RELOAD = $80000000
EndEnumeration
Enumeration 0 ; #INTERNET_OPEN_TYPE_
#INTERNET_OPEN_TYPE_PRECONFIG = 0
#INTERNET_OPEN_TYPE_DIRECT = 1
#INTERNET_OPEN_TYPE_PROXY = 3
#INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4
EndEnumeration
ProcedureDLL.s Url2Text(Url.s, AccessType.l = #INTERNET_OPEN_TYPE_DIRECT, ProxyName.s = #Null$, ProxyBypass.s = #Null$)
Protected hInet.l, hURL.l, Bytes.l, Result.s, Buffer.s{2048}
hInet = InternetOpen_(#Null$, AccessType, ProxyName, ProxyBypass, #Null)
If hInet
hURL = InternetOpenUrl_(hInet, Url, #Null$, #Null, #INET_RELOAD, #Null)
If hURL
While InternetReadFile_(hURL, @Buffer, 2048, @Bytes) And Bytes
Result + Left(Buffer, Bytes)
Wend
InternetCloseHandle_(hURL)
EndIf
InternetCloseHandle_(hInet)
EndIf
ProcedureReturn Result
EndProcedure
;-
;- TEST
;-
a$ = Url2Text("http://michel.dobro.free.fr/")
b$ = Url2Text("http://michel.dobro.free.fr/bidouilles/SPH.txt")
Debug a$
Debug b$