Shiny Language Reference
Language Reference > Web Functions
wreadbytes
bool wreadbytes(web WebVar, string Dest, int Bytes);
Synonyms:
bool webreadbytes(web WebVar, string Dest, int Bytes);
Reads N bytes from a website
The WREADBYTES statement reads a specified number of bytes from a URL resource previously opened by WOPEN.
The WOPEN and WREADBYTES statements operate on "raw" HTTP connections. Therefore when you open and read the first line of a URL you will receive the HTTP header, followed by the raw HTML. A sequence of data may look like this:
GET / HTTP/1.1
Host: www.amazingbrass.co.uk
Connection: close
Accept-Encoding: gzip
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7
<html>
<head>
....remainder of html....The data above is a sample of what you may receive, the actual data is dependant on the webserver, any error conditions etc. It is your responsibility to process this data as you see fit, in other words if you only require the HTML "web page" part of the HTTP data then you must loop through the data received until you find the <HTML> tag.
Parameters
WebVar
A variable declared as type WEB which has previously been associated with a website by using WOPEN.
Dest
A string variable that receives the line of text read from the site.
Bytes
The number of bytes to read from the site
Return Value
TRUE if reading from the site suceeded and there is further data left. Testing for FALSE is used to determine if the end of the resource has been reached.
Example Code
web MySite;
if(wopen(MySite, "http://www.amazingbrass.co.uk") == TRUE)
{
 bool bMoreData = TRUE;
 
 while(bMoreData)
 {
   // DataIn receives the web page 10 bytes at a time
   string DataIn;
   bMoreData = wreadbytes(MySite, DataIn, 10);
 }
}