Download file
Monkey Forums/Monkey Programming/Download file| 
 | ||
| Have someone a idea how can i download a file with monkey here is my code for c++ tool. but the downloaded file is empty. a time ago i got OK-answer from server. but i do not know how to get the file... EDIT: MY CODE WORKS NOW 
Strict
Import brl.tcpstream
Import brl.filestream
Function Main:Int ()
    Local stream:TcpStream=New TcpStream()
    
    If Not stream.Connect("images.wikia.com", 80)
        Print "Failed to connect!"
        Return 0
    Else
	    Print "Connected!"
    Endif
    
    
    Local file:FileStream = FileStream.Open("file.jpg", "w")
    
    If file = Null Then
       	Print "Failed to open file!"
       	Return 0
	Else
		Print "File opened!"
	End
    
    stream.WriteLine "GET /oots/images/a/a9/Example.jpg HTTP/1.0"
    stream.WriteLine "Host: images.wikia.com"
    stream.WriteLine "Connection: Close"
    stream.WriteLine ""
    Local buffer:DataBuffer
    While Not stream.Eof()
        buffer=stream.ReadAll()
        If buffer <> Null Then
        	file.WriteAll(buffer, 0, buffer.Length())
			buffer.Discard()
	        buffer = Null
       End
    Wend
    
    stream.Close
    file.Close()
    
    Print "END"
    Return 0
End
 |