httpget

HTTPGET$
The httpget$ function uses the HTTP protocol to get the contents of a web document using a URL. The document is returned as a string.

Syntax: HTTPGET$(urlExpr$) - Perform an HTTP GET and return the result

This demo retrieves the index page at http://libertybasic.com and prints the results.

code format="vbnet" 'Retrieve the webpage at libertybasic.com 'and print it. print httpget$("http://libertybasic.com") code

The next demo assigns the contents of the "What's New" Liberty BASIC page to a string variable, then prints that variable.

code format="vbnet" 'The function can also be used this way. 'The web page news.html is assigned to the 'string variable stuff$, then printed stuff$ = httpget$("http://libertybasic.com/news.html") print stuff$ code

Other kinds of files can be retrieved with this function. The following demo, modified from one that was shared by Carl, retrieves an image file with HTTPGET$. It then creates a binary file on disk and writes the results of HTTPGET$ to disk. The disk file image is then loaded with LOADIMAGE and displayed in a graphic object.

code format="vbnet" 'To retrieve an image file, assign it to 'a string variable: pic$ = httpget$("http://libertybasic.com/lb3banner.jpg")

'Create a disk file, then write the 'image information to disk. open "zzz.jpg" for binary as #1 print #1, pic$ close #1

'Load the image and display it in a graphic object. loadimage "banner", "zzz.jpg" graphic #g, 500, 100 render #g code
 * 1) g drawimage("banner",0,0)