Reading file from internet..

Blitz3D Forums/Blitz3D Programming/Reading file from internet..

I couldn't get it to work using the file commands. I'd suggest that you use the TCP commands instead. Check out the docs for the 'OpenTCPStream' command for more info.

Note that the actual file contents will begin after the first blank line in the file is encountered. The text preceeding that is the tcp header.

eg.
connection = OpenTCPStream ( "www.darknimbuspro.com", 80)

If connection

	Print "Connected! Sending request..."
	
	WriteLine connection,"GET <a href="http://www.darknimbuspro.com/RO.txt" target="_blank">http://www.darknimbuspro.com/RO.txt</a> HTTP/1.0" 
	WriteLine connection, Chr$( 10 )

	If Not Eof( connection )

		Print "Request sent. Waiting for reply..."
	
		While Not Eof( connection )
		
			Print ReadLine( connection )
			
		Wend

		Print "All data received."
		
	Else

		Print "ERROR: Failed to send request."
		
	EndIf

CloseTCPStream connection ; EDIT - Forgot to include this command.

Else

	Print "ERROR: Failed to connect to server."
	
EndIf

Print "Press a key to quit."

WaitKey

End