URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine.

1 URL object

You can use create a URL object by simply using the URL constructor. URL allows to emulate Wget console behavour and get easily content data from URL.

URL Object can retrieve Text or Binary content from URL directly by using getter methods.

1.1 Get text

getText() allows to retrieve text content from URL. By default, this method tries to get encoding from URL source but if encoding cannot be determined, UTF-8 is used. You can also determine teh text encoding passing it as parameter. (e.g. getText("ISO-8859-1") or getText("Latin-1") )

Copy
<script>
    var url = new Ax.net.URL("https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv");
    console.log(url.getText());
</script>
John,Doe,120 jefferson st.,Riverside, NJ, 08075
Jack,McGinnis,220 hobo Av.,Phila, PA,09119
"John ""Da Man""",Repici,120 Jefferson St.,Riverside, NJ,08075
Stephen,Tyler,"7452 Terrace ""At the Plaza"" road",SomeTown,SD, 91234
,Blankman,,SomeTown, SD, 00298
"Joan ""the bone"", Anne",Jet,"9th, at Terrace plc",Desert City,CO,00123

1.2 Get bytes

getBytes() method retrieves URL content as binary and returns a byte array. You can use this byte array and save it as a file, or construct a SQL blob variable to update content in database.

This method only retrieves content data and you cannot explore any characteristics like file name or content type from URL.

Copy
<script>
    var url  = new Ax.net.URL("https://apod.nasa.gov/apod/image/1902/RedSprites_Broady_960.jpg");
    var bytes = url.getBytes();
    
    var blob = new Ax.sql.Blob(bytes);
    return blob;
</script>

1.3 Get Blob

Using method getBlob() returns URL contents as a Blob. If you want to use content to insert or update into database, this is the prefered method.

getBlob() allows to explore URL stream and if file name is not received as "content-disposition" header, this method gets name from URL and configures Blob Object accordingly.

Copy
<script>
    var url  = new Ax.net.URL("https://apod.nasa.gov/apod/image/1902/RedSprites_Broady_960.jpg");
    return url.getBlob();
</script>