GLBasic User Manual

Main sections

NETWEBGET


contents$ = NETWEBGET$(server$, path$, port%, max_length%, timeout%=5000)
contents$ = NETWEBGET$(proxy$, server_and_path$, proxy_port%, max_length%, timeout%=5000)



Reads the contents of a web server to a string variable. See the parameter description below.


ok% = NETWEBGET(server$, path$, port%, local$, timeout% = 5000)
ok% = NETWEBGET(proxy$,server_and_path$, proxy_port%, local$, timeout%=5000)


Reads the contents of a website to a local file.

server$ - server name, do not start with http://. eg: "www.glbasic.com"
path$ - path on the server, has to begin with / eg: "/index.html"
port% - port to open. Usually 80
max_length% - the maximum number of characters to be read from the website. Be sure to give enough space here. The web server sends a header before the data that GLBasic internally parses out. A value of 1024 seems reasonable.
proxy$ - the name of your proxy server (if you have one) eg: "proxy.mycompany.com".
proxy_port% - the port number of your proxy server (if you have one) eg: 8080.
local$ - the local filename to write the contents of the webpage to.
timeout% - the timeout if no connection was established in milliseconds.

The NET... commands give network functionality to GLBasic programs using the TCP protocol. TCP has the advantage over other protocols that sending and receiving of network messages is ensured.

NOTE : This command requires that you have purchased either GLBasic Premium or the GLBasic NET add-on.

Example :
FUNCTION ReadHighScores: names$[], scores[], username$, thescore
LOCAL ct, i, str$, proxy$, port

    str$ = "highscores/listgame.php"
    str$ = str$ + "?game=mygame"
    str$ = str$ + "&name="+username$
    str$ = str$ + "&score="+thescore
    str$ = str$ + "&secret=mycode"

    PRINT ".: WebGet scores :.", 0, 0
    SHOWSCREEN

    INIOPEN "config.ini"
    proxy$ = INIGET$("server", "proxy")
    port = INIGET$("server", "port")
    KILLFILE "scores.ini"
    IF port=0 OR proxy$="NO_DATA"
        NETWEBGET("www.glbasic.com", "/"+str$, 80, "scores.ini")
    ELSE
        NETWEBGET(proxy$, "http://www.glbasic.com/" + str$, port, "scores.ini")
    ENDIF

    INIOPEN "scores.ini"
    ct = INIGET$("scores", "count")
    DIM names$[ct]
    DIM scores[ct]

    FOR i=1 TO ct
        names$[i-1] = INIGET$("scores", "n"+i)
        scores[i-1] = INIGET$("scores", "s"+i)
    NEXT
ENDFUNCTION


Proxy example :
Note : There is currently no way to specify a username and password for the proxy server.
local ok%
local myproxy$
local port
proxy_host$ = INIGET$("server", "proxy") // eg. proxy.mycompany.com
proxy_port = INIGET$("server", "port") // eg. 8080

ok% = NETWEBGET(proxy_host$,"http://timegenie.com/city.time/ausyd", proxy_port, "htmloutput.html")


Example :
This example demonstrates how to read a set number of characters (in this example, 512) into a file
local contents$

contents$ = NETWEBGET$("www.glbasic.com", "index.php", 80, 512)

Or the same with a proxy server :
local ok%
local myproxy$
local port
proxy_host$ = INIGET$("server", "proxy") // eg. proxy.mycompany.com
proxy_port = INIGET$("server", "port") // eg. 8080

ok% = NETWEBGET(proxy_host$,"http://timegenie.com/city.time/ausyd", proxy_port, 512)

See also...