First Steps
Since every SIMPOL program begins with the function main()
, that
is where we will start. The image below shows the beginning of the project. At this very
early stage, there is not much there. The httpresponse type is also not
in blue, but instead it is in black. That is a sign that the library is not yet part of
the project.
To resolve this, we can add the required library to the project. From the
Project Settings dialog. Select the second tab,
Includes and libraries, and then click on the
button next to the
(*.sml) Libraries to link; label. From there, enter the SIMPOL
lib
directory and pick the
httpclientlib.sml
file. The result should
look like the image below:
At this point, clicking on the httpclientlib.sml
library requires the SIMPOL
component sock
and therefore this will also be added to the project.
This is quite handy, since otherwise the library wouldn't even work. The warning dialog
looks like this:
Depending on the size of the screen area on our computer, it may be useful to turn off a couple of windows while writing the program. This can be done from the
menu, by selecting the and items, for example. After a bit more code has been written, and with our new adjusted windows, the result might look like the following image.At this point, let's actually have a look at our first version of this program.
urldump.sma
constant sERRTXT_PAGE "Page '" constant sERRTXT_NOTFOUND "' not found" constant sERRTXT_SUCCESS "' successfully retrieved" constant sERRTXT_FILEOPENFAILED "Error opening output file" constant sCRLF "{d}{a}" function main(string sUrl, string sOutfile) string errtext integer e fsfileoutputstream fpo httpresponse response if sUrl <= "" errtext = usage() else response =@ httpget(sUrl) if response !@= .nul if response.errorstatus > "" errtext = response.errorstatus else if sOutfile > "" e = 0 fpo =@ fsfileoutputstream.new(sOutfile, error=e) if fpo =@= .nul or e != 0 errtext = sERRTXT_FILEOPENFAILED + sCRLF else if response.statuscode < 200 or \ response.statuscode >= 300 errtext = sERRTXT_PAGE + sUrl + \ sERRTXT_NOTFOUND + sCRLF else errtext = sERRTXT_PAGE + sUrl + sERRTXT_SUCCESS + sCRLF end if fpo.putstring(.if(response.entitybody != .nul, \ response.entitybody.getstring(1, .inf, 1), ""), 1) end if else if response.statuscode < 200 or response.statuscode >= 300 errtext = sERRTXT_PAGE + sUrl + sERRTXT_NOTFOUND + sCRLF else errtext = "" end if errtext = errtext + .if(response.entitybody != .nul, \ response.entitybody.getstring(1, .inf, 1), "") end if end if end if end function errtext function usage() string s s = "smprun[32.exe] urldump.smp <url> <outputfile>{d}{a}" end function s