|
Whitebeam Template Reference Documentation
|
HttpRequest Template
doRequest()
Send a request to a remote HTTP server.
Syntax
number = rb.HttpRequest.doRequest()
Parameters
The 'doRequest' method takes no parameters
Results
The 'doRequest' method returns number:
Type/Value | Range/Length | Description |
number |
  |
HTTP result code returned from the remote server, or -1 if the server could not be contacted.
|
Remarks
This methods creates an HTTP request and sends the message to a remote server. The request
makes used of use of the properties set on the object before calling this method.
Example The following simple example reads the contents of the Whitebeam homepage (www.whitebeam.org) and extracts all the
anchor tags with 'href' attributes. These links are then formatted into a simple HTML table.
var request = new HttpRequest;
request.url="http://www.whitebeam.org";
request.method="GET";
request.doRequest();
if (request.res==200) {
// Create a parser.
var aParser = new XmlParser(rb.xml);
// Build the tree.
if (aParser.build(request.body)) {
// Find all the anchor tags with href attributes using XPath.
var bodyTag = aParser.root.select("//a[@href]");
// Display all the links we find.
for (var i=0;i<bodyTag.length;i++) {
// Write to the client.
rb.page.write(">tr><td>"+bodyTag[i].execute().text()+"</td></tr>\n");
}
}
else {
rb.page.write("Couldn't build XML Tree - text contains errors!");
}
}
A separate XML tutorial explains how to use the XML features of Whitebeam |
|
(loadtime : 14ms) |