Retreiving a web page?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
To get the webpage we can use wininet.dll too
(InternetOpen, InternetOpenUrl, InternetReadFile and InternetCloseHandle functions) BUT the problem remains the same... the buffer.
How can we work arround it?
Here's how I download a file (or URL) with Visual Basic that is very reliable and has never failed to work for me. Perhaps someone can translate it to its PureBasic equivalent?

Code: Select all

' Download a file (or URL) from the Internet

Dim url As String, filedata As String
url = "[url]http://www.google.com/images/logo.gif[/url]"

hOpen = InternetOpen("VB OpenUrl", 0, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, url, vbNullString, 0, &H80000000, 0)
bDoLoop = True
While bDoLoop
    iBuffer = vbNullString
    bRet = InternetReadFile(hOpenUrl, iBuffer, Len(iBuffer), bytesread)
    filedata = filedata & Left(iBuffer, bytesread)
    If Not CBool(bytesread) Then bDoLoop = False
Wend
If hOpenUrl  0 Then InternetCloseHandle (hOpenUrl)
If hOpen  0 Then InternetCloseHandle (hOpen)

MsgBox filedata 

' To save to disk (add required extension of downloaded file):
Open "c:\file" For Binary Access Write As #1
    Put #1, , filedata 
Close #1

PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

Paul's code worked perfectly for me without any change.

Bye,

Juan Calderón Alonso
Registered user
Post Reply