SIMPOL Documentation

Understanding the Code

Although there is not much to this program, it covers a number of concepts that are worth exploring. To begin with, the command line parameters are always string variables and they do not allow for default values, so to set those you will need to write some code for it. At the beginning of the program, there is a test for the sUrl variable. If it finds that no value has been passed, then it calls the usage() function. This approach makes it quite easy to both document how the program works and also inform the user when the parameters are not correct.

The next thing to note is the call to the httpget() function. That returns an httpresponse object (and should do so under all circumstances, so the following test for .nul may be unnecessary). The httpresponse object contains all the information that is a result of the attempt to retrieve the resource represented by the sUrl variable. Should there have been any unexpected problem with the retrieval of the resource then the errorstatus property would have some value greater than the empty string ("").

The remaining code simply checks whether the output is going to a file or if it will be output as part of the return value. In each case, it outputs the content of the entitybody property if the retrieval was successful (a value between 200 and 299 in the statuscode property) then a success string is returned, otherwise an error string.