
Finally figured out how to do a HTTP GET request. The trick was to add two empty lines, as the server expects four lines. I post it here so I can look it up in case I forget how it works.
Code: Select all
' # --------------------------------
' # HTTP GET example in HiSoft Basic
' # api call to openweathermap.org
' # --------------------------------
' include HiSoft Networld lib; REM is NOT a remark but part of the call!
' requires STiK
REM $include networld.bas
' my details
server$="api.openweathermap.org"
city$="Cuijk,NL"
appid$="blahblah"
' create request
getme$="/data/2.5/find?q="+city$+"&units=metric&mode=xml&appid="+appid$
crlf$=CHR$(13)+CHR$(10)
request$="GET "+getme$+" HTTP/1.1"+crlf$+"Host: "+server$+crlf$+crlf$+crlf$
' connect to server at port 80
PRINT "Connecting..."
cn=tcp_connect(server$,80,tos,2000)
wait(0.5) 'needs some time, might be less than 0.5
' send request
x=tcpsend(cn,request$)
wait(0.5) 'again needs some time
' get reply from server and print to screen
c=cnbyte_count(cn)
IF c>0 THEN
FOR f=1 TO c
d=cnget_char (cn)
PRINT CHR$(d);
NEXT
END IF
' close connection
x=tcp_close(cn,20)
' wait routine
SUB wait(sec!)
STATIC starttime!, waiting!
waiting! = 0
starttime! = TIMER
WHILE waiting! <= sec!
waiting! = TIMER - starttime!
WEND
END SUB
