
Chez moi ça marche bien. Pouvez vous essayer chez vous ?
Parcontre il y a 2 chose que je ne sais pas trop comment faire
Pour virer l'entête et pourquoi lorsque je telecharge en local j'ai mon fichier entourré d'une valeur au debut et d'un Zero a la fin.
Code : Tout sélectionner
Structure ProxyStructure
Adr.s
Port.l
login.s
password.s
EndStructure
Global Proxy.ProxyStructure
Proxy\Adr="xxxxxxxxxxxx" ;Url ou IP
Proxy\Port=xxxx ;Numero de port
Proxy\login="" ;Le login si il y en a un
Proxy\password="";Le mot de passe si il y en a un
InitNetwork()
Procedure.s MyDownload(Url.s,UseProxy=#False)
Protected Server.s,Port.l,conc$,enc$,Header.s,Res.l,*Buffer = AllocateMemory(1024),String.s,DataLength.l
;Si j'ai un Proxy je dois me connecter au Proxy
If UseProxy=#True
Path.s=Url
Server.s=Proxy\Adr
Port.l=Proxy\Port
conc$=Proxy\login+":"+Proxy\password
OutputBuffer = AllocateMemory(Len(conc$)*4)
Base64Encoder(@conc$,Len(conc$),OutputBuffer,Len(conc$)*4)
enc$=PeekS(OutputBuffer)
;Si je n'ai pas de proxy on se connecte directement au serveur
ElseIf UseProxy=#False
Port=80
Path.s = Url
Url.s = RemoveString(Url,"http://",1)
i = FindString(Url,"/",1)
If i
Server = Left(Url,i-1)
Else
Server = Url
EndIf
EndIf
;Connection au Serveur
ConnectionID = OpenNetworkConnection(Server, Port)
If ConnectionID
;Creation de l'entête a envoyer
Header ="GET "+Path+" HTTP/1.1"+#CRLF$
If UseProxy=#True
Header + "Proxy-Authorization: Basic "+enc$+#CRLF$
Else
Header + "Host: "+Server+#CRLF$+#CRLF$
EndIf
Header+#CRLF$
Debug Header
Res=SendNetworkData(ConnectionID,@Header,Len(Header))
Delay(10)
result = NetworkClientEvent(ConnectionID)
Repeat ;On lit les données qui arrive
DataLength = ReceiveNetworkData(ConnectionID,*Buffer,1024)
String + PeekS(*Buffer,DataLength)
Until DataLength<1024
FreeMemory(*Buffer) ;POuff! Pu besoin on efface
MessageRequester("Done!","Your Data" + Chr(13) + Chr(10) + Trim(String),0)
;C'est finit on se deconnecte
CloseNetworkConnection(ConnectionID)
ProcedureReturn String
EndIf
EndProcedure
String.s=MyDownload("http://fr.yahoo.com",#True)
; If CreateFile(0,"test.txt")
; WriteData(0,@String,Len(String))
; CloseFile(0)
; EndIf
; RunProgram("test.txt")
String.s=MyDownload("http://localhost/",#False)