*SOLVED* HTTP GET request in HiSoft Basic

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
User avatar
robv
Captain Atari
Captain Atari
Posts: 219
Joined: Mon Nov 09, 2020 7:39 pm
Location: Netherlands

*SOLVED* HTTP GET request in HiSoft Basic

Post by robv »

As I am probably the only one using HiSoft Basic, this is basically a 'note to self'. :wink:
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
So now that I can do this, all I need to do is add a few lines to turn it into a modern browser. Or am I underestimating something? :lol:
Rob
engaged with Atari ST since 1987
http://acwot.atari-users.com
User avatar
LaceySnr
Captain Atari
Captain Atari
Posts: 231
Joined: Wed Jun 26, 2013 5:00 am
Contact:

Re: *SOLVED* HTTP GET request in HiSoft Basic

Post by LaceySnr »

Something something https something :)

Nice work though, that's cool to have available!
User avatar
christos
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2529
Joined: Tue Apr 13, 2004 8:24 pm
Location: Greece

Re: *SOLVED* HTTP GET request in HiSoft Basic

Post by christos »

Nice! There are two problems, it's next to impossible to find http APIs (not Https) and most of them return JSON so you'd need a JSON parser. It's really cool though.
I wonder if there's something similar for GFA. I ll have to dig a bit...
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2955
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: *SOLVED* HTTP GET request in HiSoft Basic

Post by charles »

truely amazing

hocus pocus that really works

cool stuff!!
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
Post Reply

Return to “Other BASIC”