Basic Univers
; Nom du fichier à downloader
File$ = "http://luchezl.free.fr/Autres/ping_pong.zip"

;/ HTTP Example


#HTTP_Ok = 1
#HTTP_Error = 0
#HTTP_ProxyData_Needed = - 2
#HTTP_Authentication_Needed =- 3
#HTTP_Invalid_URL = - 4
#HTTP_FileNotFound = - 5
#HTTP_FileMoved = - 6
#HTTP_TimeOut = - 7
#HTTP_UnknowFileSize = - 8
#HTTP_UnknowDate = - 9
#HTTP_Downloading = 2
#HTTP_DownloadEnd = 3

#HTTP_Action_Get2File = 2
#HTTP_Action_Get2Mem = 3
#HTTP_Action_GetInfo = 4



If HTTP_Init()
  
  Debug "Change incoming buffer"
  Debug "Old size:" + Str(HTTP_Get_InBuffer())
  HTTP_Set_InBuffer(8192)
  Debug "New size:" + Str(HTTP_Get_InBuffer())
  
  
  Debug "---------------------"
  Debug "setting proxy data"
  HTTP_Set_Proxy("", "", 8080, "", "") ; only needed if you are behind a proxy server

  restart:
  Debug "---------------------"
  Debug "connecting"
  Result = HTTP_New_Connection(File$, 80)
  
  

  
  If Result>0 ; All error are negative numbers
    
    size.l = HTTP_File_Size(Result)
    Debug "---------------------"
    Debug "file size: " + Str(size)+"bytes"
    Debug "date: " + FormatDate("%dd - %mm - %yyyy", HTTP_File_Date(Result))
    Debug "---------------------"
    Debug "getting file to harddisk..."
    If HTTP_Download_ToFile(Result, "p2b_direct.zip")
      Repeat
        current.l = HTTP_Get_Progress(Result)
        Debug current
        Delay(200)
      Until size = current
    Else
      Debug "---------------------"
      Debug "error: " + HTTP_LastError_Description()
    EndIf
    
    memory = AllocateMemory(size)
    Debug "---------------------"
    Debug "getting file to memory..."
    If HTTP_Download_ToMem(Result, memory)
      Repeat
        current.l = HTTP_Get_Progress(Result)
        Debug current
        Delay(200)
      Until size = current
      If CreateFile(0, "teste_memory.zip")
        WriteData(memory, size)
        CloseFile(0)
      EndIf
    Else
      Debug "---------------------"
      Debug "error: " + HTTP_LastError_Description()
    EndIf
    
  Else
    Debug "---------------------"
    Debug "error: " + HTTP_LastError_Description()
    If HTTP_LastError_ID()=#HTTP_Authentication_Needed
      Debug "---------------------"
      Debug "setting www authorization"
      HTTP_Set_Authorization(Result, "", "")
      Goto restart
    EndIf
  EndIf
  
  Delay(500)
  HTTP_Stop()
  
EndIf